sparkyrose
Registered User.
- Local time
- Today, 17:58
- Joined
- Sep 12, 2007
- Messages
- 31
Hi all,
My db exports a query to an excel file (specifically a .csv file) with address data. I need to format the zip code column to the Excel Zip Code format before saving (otherwise leading zeros are omitted).
After searching this forum I found an old discussion (from 2005) that seemed like it would work but I'm having a problem closing the instance of Excel that is created in the code. The application hangs until I manually close it in Task Mgr.
Stepping through the code line by line it is fine until the Close / Quit part (see below).
If anyone can help I'd be very grateful.
This is my code:
It gets called from a separate Sub as follows:
My db exports a query to an excel file (specifically a .csv file) with address data. I need to format the zip code column to the Excel Zip Code format before saving (otherwise leading zeros are omitted).
After searching this forum I found an old discussion (from 2005) that seemed like it would work but I'm having a problem closing the instance of Excel that is created in the code. The application hangs until I manually close it in Task Mgr.
Stepping through the code line by line it is fine until the Close / Quit part (see below).
If anyone can help I'd be very grateful.
This is my code:
Code:
Public Sub ModifyExportedExcelFileFormats(sFile As String)
'On Error GoTo Err_ModifyExportedExcelFileFormats
Application.SetOption "Show Status Bar", True
vStatusBar = SysCmd(acSysCmdSetStatus, "Formatting export file... please wait.")
Dim xlApp As Object
Dim xlSheet As Object
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open(sFile).Sheets(1)
With xlApp
.Application.Sheets("BatchProcess").Select
.Application.Cells.Select
.Application.Selection.ClearFormats
.Application.Columns("I:I").Select
.Application.Selection.EntireColumn.NumberFormat = "00000"
.Application.Activeworkbook.Save
.Application.Activeworkbook.Close
.Application.Quit
End With
Set xlApp = Nothing
Set xlSheet = Nothing
vStatusBar = SysCmd(acSysCmdClearStatus)
Exit_ModifyExportedExcelFileFormats:
Exit Sub
'Err_ModifyExportedExcelFileFormats:
' vStatusBar = SysCmd(acSysCmdClearStatus)
' MsgBox Err.Number & " - " & Err.Description
' Resume Exit_ModifyExportedExcelFileFormats
End Sub
It gets called from a separate Sub as follows:
Code:
DoCmd.TransferText acExportDelim, , "qryUPSExportFirst", "S:\Programming\MFNDb\BatchProcess.csv", False
Call ModifyExportedExcelFileFormats("S:\Programming\MFNDb\BatchProcess.csv")