B
BarryM
In Access 97 I want to open some Excel files at the same time without
creating more than one instance of Excel.
The following code works but it causes Excel to close if an individual file
is closed, but not if Excel is closed. The error message is “Excel has caused
an error in EXCEL.EXE. Excel will now close.†Any suggestions?
Many thanks in anticipation.
Public Sub GetExcelFile(strDoc As String)
On Error GoTo ErrDocs
Dim MyXL As Object
'Open Excel
Set MyXL = GetObject(, "Excel.Application") 'error if Excel not running
OpenDoc:
'Open the selected file
MyXL.Workbooks.Open strDoc
MyXL.Application.Visible = True
Exit Sub
ErrDocs:
Select Case Err
Case 429 'ActiveX component can't create object
'Excel not running, open it
Set MyXL = GetObject("", "Excel.Application")
GoTo OpenDoc
Case Else
MsgBox "Error " & Err & ": " & Error, 0 + 64, "Opening Excel Files"
End Select
End Sub
creating more than one instance of Excel.
The following code works but it causes Excel to close if an individual file
is closed, but not if Excel is closed. The error message is “Excel has caused
an error in EXCEL.EXE. Excel will now close.†Any suggestions?
Many thanks in anticipation.
Public Sub GetExcelFile(strDoc As String)
On Error GoTo ErrDocs
Dim MyXL As Object
'Open Excel
Set MyXL = GetObject(, "Excel.Application") 'error if Excel not running
OpenDoc:
'Open the selected file
MyXL.Workbooks.Open strDoc
MyXL.Application.Visible = True
Exit Sub
ErrDocs:
Select Case Err
Case 429 'ActiveX component can't create object
'Excel not running, open it
Set MyXL = GetObject("", "Excel.Application")
GoTo OpenDoc
Case Else
MsgBox "Error " & Err & ": " & Error, 0 + 64, "Opening Excel Files"
End Select
End Sub