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
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