How to fatch Range's from an excel sheet when the file is on netwo

M

Manmohan Singh

hi All
i write a function to find the Ranges in excel sheet.My excel sheet
shoul be on network. i map that path from my local machine.
now when we publish my site a want to find the range of that excel sheet it
shows " Object variable or with Block bariable not set."




Tthis is my function--where Filename -Z:\inventory.xls, Z:\ is my map Drived
from server.



Friend Function GetExcelRange(ByVal Filename As String)

Dim ExcelAPP As Object
Dim inc As Integer = 0
Dim RangeString As New StringBuilder
Try
ExcelAPP = CreateObject("Excel.Application")
ExcelWorkBook = ExcelAPP.Workbooks.Open(Filename:=Filename)
ExcelSheet = ExcelWorkBook.Worksheets
If ExcelWorkBook.Names.Count = 0 Then
MsgBox("Error: No name ranges in this excel file",
MsgBoxStyle.Critical, "Metamation")
Return RangeString.ToString()
End If
While Not inc = ExcelWorkBook.Names.Count
If inc = 0 Then
RangeString.Append(ExcelWorkBook.Names.Item(inc + 1).Name)
Else
RangeString.Append("," & ExcelWorkBook.Names.Item(inc +
1).Name)
End If

inc += 1
End While

Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Metamation")
Finally
ExcelAPP.ActiveWorkbook.Close()
ExcelAPP.Quit()
ExcelAPP = Nothing
End Try

Return RangeString.ToString()
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top