>Can someone tell me what is causing my open file code to fail with the error ' invalid object reference'
>
>Private Sub Command1_Click()
>Dim xl As Object
>
>Set xl = CreateObject("Excel.Sheet")
>
>xl.application.Visible = True
>xl.application.open "c:\test.xls" 'valid file name
>xl.Open "c:\temp.csv"
>
>
>Set xl = Nothing
>End Sub
>
>
>Thank you
This this instead:
1st, set a reference to Excel in the Project/Reference menu
Then use this code:
Dim xl As Excel.Application
Set xl = New Excel.Application
xl.Visible = True
xl.Workbooks.Open "MyFile.xls"
'processing here
xl.ActiveWorkbook.Close
Set xl = Nothing