DimlyLitMind
New Member
- Joined
- Apr 24, 2014
- Messages
- 4
Hi all,
I am trying to run a VBA code in Access to open an excel file and export some data into it. This has worked before with Excel 2003. I had to recently migrate to Excel 2007 and I am getting various errors one by one, but at this point I am stuck at this particular step of opening an Excel file. The file is present, the path is correct (I checked while debugging the VBA code) and I get an error. The problem is, the Err.Description field is blank. In fact, everything in Err object is either blank or 0. Can someone help me? This is EXTREMELY URGENT. Thanks!!!
Here's my code:
I am trying to run a VBA code in Access to open an excel file and export some data into it. This has worked before with Excel 2003. I had to recently migrate to Excel 2007 and I am getting various errors one by one, but at this point I am stuck at this particular step of opening an Excel file. The file is present, the path is correct (I checked while debugging the VBA code) and I get an error. The problem is, the Err.Description field is blank. In fact, everything in Err object is either blank or 0. Can someone help me? This is EXTREMELY URGENT. Thanks!!!
Here's my code:
Code:
On Error Resume Next
' try to open Excel
Set exlApp = CreateObject("Excel.Application")
RunExcelBeforeDataTransfer = False
If LoadExcel = False Then
Exit Function
End If
Set wrkBook = exlApp.Workbooks(strFSFileName)
If 0 = Err.Number Then 'a workbook with this name is OPEN. Close it first.
exlApp.Workbooks(strFSFileName).Close SaveChanges:=False
End If
Err.Clear
On Error GoTo ErrorHandler
Call Log("Opening Excel file: " & strThisAppPath + strFSFileName)
Set wrkBook = exlApp.Workbooks.Open(strThisAppPath + strFSFileName, 0, False)
exlApp.Run (strFSFileName & "!GeraFormatBeforeDataTransfer")
exlApp.Workbooks(strFSFileName).Close SaveChanges:=True
UnLoadExcel
RunExcelBeforeDataTransfer = True
Exit Function
ErrorHandler:
UnLoadExcel
Call Log("Error preparing Excel for data transfer: " & CStr(Err.Number) & " - " & Err.Description & Err.Source)
AppError "Error preparing Excel for data transfer: " & CStr(Err.Number) & " - " & Err.Description & Err.Source
Err.Raise vbObjectError + 1, "", ""
End Function