yeungsprite
Programmer
This should be an easy question, but as a novice programmer, I am not sure how to solve it. If I have the simple code below:
Private Sub Command1_Click()
Dim ExcelApp As Excel.Application 'Excel-object
Dim colRange As Range ' Column in which to read values from
Dim i As Range ' value of the current cell
Set ExcelApp = New Excel.Application
ExcelApp.Application.Visible = True
'Initialize and show Excel application and Import file
ExcelApp.Workbooks.Open "C:\somefile"
Set colRange = ActiveSheet.Range("A1", ActiveSheet.Cells.SpecialCells(xlLastCell)) 'error appears here
For Each i In colRange
Next i
'Disable 'save on close' dialog boxes
ExcelApp.ActiveWorkbook.Saved = True
ExcelApp.Workbooks.Close
'end application
ExcelApp.Quit
Set ExcelApp = Nothing
End Sub
why does the Run-time error '91'-> "Object variable or With block variable not set" occur if I run the function more than once?? It has something to do with the 'Set' call. Please help!! Your help is greatly appreciated.
Thanks in advance.
Private Sub Command1_Click()
Dim ExcelApp As Excel.Application 'Excel-object
Dim colRange As Range ' Column in which to read values from
Dim i As Range ' value of the current cell
Set ExcelApp = New Excel.Application
ExcelApp.Application.Visible = True
'Initialize and show Excel application and Import file
ExcelApp.Workbooks.Open "C:\somefile"
Set colRange = ActiveSheet.Range("A1", ActiveSheet.Cells.SpecialCells(xlLastCell)) 'error appears here
For Each i In colRange
Next i
'Disable 'save on close' dialog boxes
ExcelApp.ActiveWorkbook.Saved = True
ExcelApp.Workbooks.Close
'end application
ExcelApp.Quit
Set ExcelApp = Nothing
End Sub
why does the Run-time error '91'-> "Object variable or With block variable not set" occur if I run the function more than once?? It has something to do with the 'Set' call. Please help!! Your help is greatly appreciated.
Thanks in advance.