Type Mismatch opening Excel File from Access 2000

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

I have written code to create an instance of Excel and
then use the GetObject to open a file. Everything is oK
until the XL file is being opened at which time the
prompt for 'do you wish to enable/disable macros'
appears'. On choosing 'yes' the code crashes with Error
#13 Type Mismatch. sample code below

Dim objXL As New Excel.Application
Dim Path As String

Set objXL = GetObject(Path, "Excel.Sheet")
objXL.Visible = True
 
You've declared objXL to be an Excel.Application object, yet you're trying
to assign an Excel.Sheet object to it.

Try:

Dim objXL As Excel.Application
Dim Path As String

Set objXL = New Excel.Application
With objXL.Application
.Workbooks.Open Path
.Visible = True
End With
 
Back
Top