JohanGduToit
Board Regular
- Joined
- Nov 12, 2021
- Messages
- 89
- Office Version
- 365
- 2016
- Platform
- Windows
Afternoon Experts,
I have an MS Access application that reformat an Excel spreadsheet that are imported into a MS Access table once reformatting has been completed. The only reformatting that takes place is a deletion of a worksheet named "Sum" and then deleting all 'empty' rows from the last cell in Column "A" that contains data to the end of the file. The code executes without any error; but the Excel Application remains open afterwards. So if I run the code again to format a 2nd Excel file, the program crash on line
For some reason Excel do not close once code has been executed.
Please assist? I think this may have something to do with late/early binding; but I am not sure though.
Thank you.
I have an MS Access application that reformat an Excel spreadsheet that are imported into a MS Access table once reformatting has been completed. The only reformatting that takes place is a deletion of a worksheet named "Sum" and then deleting all 'empty' rows from the last cell in Column "A" that contains data to the end of the file. The code executes without any error; but the Excel Application remains open afterwards. So if I run the code again to format a 2nd Excel file, the program crash on line
VBA Code:
.Application.Rows(Range("A" & .Rows.Count).End(xlUp).Offset(1).Row & ":" & .Rows.Count).Delete
For some reason Excel do not close once code has been executed.
Please assist? I think this may have something to do with late/early binding; but I am not sure though.
Thank you.
VBA Code:
Public Sub FormatPargoInvoiceFile(sFile, sSheet As String)
'On Error GoTo Err_FormatPargoInvoiceFile
Const xlUp As Long = -4162
Dim xlApp As Object
Dim xlSheet As Object
Application.SetOption "Show Status Bar", True
vStatusBar = SysCmd(acSysCmdSetStatus, "Formatting & Processing Pargo Invoice File... Please wait.")
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open(sFile).Sheets(1)
With xlApp
.Application.DisplayAlerts = False
.Application.Sheets("Sum").Delete
.Application.DisplayAlerts = True
.Application.Sheets(sSheet).Select
.Application.Rows(Range("A" & .Rows.Count).End(xlUp).Offset(1).Row & ":" & .Rows.Count).Delete
.Application.Range("A1").Select
.Application.ActiveWorkbook.Save
.Application.ActiveWorkbook.Close
.Application.Quit
End With
vStatusBar = SysCmd(acSysCmdClearStatus)
Set xlSheet = Nothing
Set xlApp = Nothing
'Exit_FormatPargoInvoiceFile:
' Exit Sub
'Err_FormatPargoInvoiceFile:
' vStatusBar = SysCmd(acSysCmdClearStatus)
' MsgBox Err.Number & " - " & Err.Description
' Set xlSheet = Nothing
' Set xlApp = Nothing
' Resume Exit_FormatPargoInvoiceFile
End Sub