Excel automation goes wrong with every 'even' attempt

J

John J.

From Access I'm trying to convert several *.htm excel files into 'real'
excel files.

Dim appExcel As Excel.Application
Dim wkb As Excel.Workbook
Dim strFile As String

Set appExcel = New Excel.Application
strFile = "D:\My documents\Test.htm"

Set wkb = appExcel.Workbooks.Open(strFile)
appExcel.Visible = True 'Do something with worksheet

ActiveWorkbook.SaveAs Filename:="D:\My documents\Test.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False

Set wkb = Nothing
Set appExcel = Nothing

The first time this code runs fine but the second time it gives the
following error:
"Object variable or block variable With is not set."

Strange thing is that the 3rd time it runs OK again, 4th time same error,
etc.

Can someone explain what's going on here?

Thank you,
John
 
J

John J.

I found the following solution:

"A Excel workbook does not have an Activeworkbook property. Also, unless you
have added a reference to Excel, then Access will not understand xlNormal as
it is part of the Excel object model. (its value is -4143)."

In this case:
appExcel.ActiveWorkbook.SaveAs
works, in stead of
ActiveWorkbook.SaveAs

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top