Option Explicit Public appWorld As Excel.Application Public wbWorld As Excel.Workbook ' Public shtWorld As Excel.Worksheet Sub Setup() ' IMPORTANT: If your machine does not have Excel 97 installed, ' you must change the reference to the Excel 95 Object Library. ' Then, in the Declarations section above, change the variable ' declaration "wbWorld as Workbook" to "shtWorld As Worksheet." ' Then change all references to "wbWorld" to "shtWorld." On Error Resume Next 'ignore errors THE FOLLOWING LINE IS THE PROBLEM!!!! Set appWorld = GetObject(, "Excel.Application") 'look for a running copy of Excel END OF PROBLEM LINE!!!! If Err.Number <> 0 Then 'If Excel is not running then Set appWorld = CreateObject("Excel.Application") 'run it End If Err.Clear ' Clear Err object in case error occurred. On Error GoTo 0 'Resume normal error processing Set wbWorld = appWorld.Workbooks.Open(App.Path & "\world.xls") End Sub
From novice to tech pro — start learning today.