[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

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

Man Mohan Singh

12/20/2006 6:33:00 AM

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