G
Guest
Greetings,
I've searched everywhere I could for a solution but have come up empty. My
issue is with the code listed below. We have an Access 97 db, attempting to
modify an Excel file. This code works with no problem when the version of
Excel is 97.
However, we need it to also work on Excel 2002 but receive the following
error:
"ERROR 1004: Open method of Workbooks class failed"
Is this a reference issue? Is doesn't seem to want to communicate with
Excel properly.
The references we have checked are:
Visual Basic for Applications
Microsoft Access 8.0 Object Library
Microsoft DAO 3.51 Object Library
Microsoft Office 8.0 Object Library
I've tried using these as well (with no luck):
Microsoft Excel 10.0 Object Library
Microsoft Office 10.0 Object Library
Any help would be appreciated!
Here's the code:
**************
Public Function XLCellFix(strTempFileName As String)
On Error GoTo Error_Handler
'Bind so that it will run on any machine
Dim oXL As Object
Set oXL = CreateObject("Excel.Application")
With oXL
'Open the passed-in XLS document
.application.Workbooks.Open (strTempFileName)
'Autofit all rows and columns for easier viewing
With .ActiveSheet.Cells
.Select
.EntireRow.AutoFit
.EntireColumn.AutoFit
End With
.ActiveSheet.Range("A1").Select
'Close document and automatcally save the changes
oXL.application.Workbooks(1).Save
.Quit
End With
Exit Function
Error_Handler:
AddToLogFile "ERROR " & Err.number & ": " & Err.Description & " ("
& Err.Source & ")", LOG_ERROR
Resume Next
End Function
*******************
Thanks in advance,
Rob M.
I've searched everywhere I could for a solution but have come up empty. My
issue is with the code listed below. We have an Access 97 db, attempting to
modify an Excel file. This code works with no problem when the version of
Excel is 97.
However, we need it to also work on Excel 2002 but receive the following
error:
"ERROR 1004: Open method of Workbooks class failed"
Is this a reference issue? Is doesn't seem to want to communicate with
Excel properly.
The references we have checked are:
Visual Basic for Applications
Microsoft Access 8.0 Object Library
Microsoft DAO 3.51 Object Library
Microsoft Office 8.0 Object Library
I've tried using these as well (with no luck):
Microsoft Excel 10.0 Object Library
Microsoft Office 10.0 Object Library
Any help would be appreciated!
Here's the code:
**************
Public Function XLCellFix(strTempFileName As String)
On Error GoTo Error_Handler
'Bind so that it will run on any machine
Dim oXL As Object
Set oXL = CreateObject("Excel.Application")
With oXL
'Open the passed-in XLS document
.application.Workbooks.Open (strTempFileName)
'Autofit all rows and columns for easier viewing
With .ActiveSheet.Cells
.Select
.EntireRow.AutoFit
.EntireColumn.AutoFit
End With
.ActiveSheet.Range("A1").Select
'Close document and automatcally save the changes
oXL.application.Workbooks(1).Save
.Quit
End With
Exit Function
Error_Handler:
AddToLogFile "ERROR " & Err.number & ": " & Err.Description & " ("
& Err.Source & ")", LOG_ERROR
Resume Next
End Function
*******************
Thanks in advance,
Rob M.