I am using the following code to format an Excel file that I am creating using:
DoCmd.OutputTo acOutputQuery, stDocName, acFormatXLS, XFile, False
Excel formatting:
******************************
Public Sub ModifyExportedExcelFileFormats(XFile As String)
On Error GoTo Err_ModifyExportedExcelFileFormats
Dim xlApp As Object
Dim xlSheet As Object
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open(XFile).Sheets(1)
With xlApp
.Application.Sheets("qrpt_DR").Select
.Application.Cells.Select
.Application.Cells.Font.Name = "Century Gothic"
.Application.Cells.Font.Size = 10
.Application.Selection.Columns.AutoFit
.Application.Selection.Rows.AutoFit
.Application.ActiveWorkbook.Save
.Application.ActiveWorkbook.Close
.Quit
End With
Set xlApp = Nothing
Set xlSheet = Nothing
Exit_ModifyExportedExcelFileFormats:
Exit Sub
Err_ModifyExportedExcelFileFormats:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_ModifyExportedExcelFileFormats
End Sub
***************************
However, I get the error message:
-214741851 - Method 'Save' of Object '_Workbook' failed. I have not been able to find any information on the error message and how to get around it.
DoCmd.OutputTo acOutputQuery, stDocName, acFormatXLS, XFile, False
Excel formatting:
******************************
Public Sub ModifyExportedExcelFileFormats(XFile As String)
On Error GoTo Err_ModifyExportedExcelFileFormats
Dim xlApp As Object
Dim xlSheet As Object
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open(XFile).Sheets(1)
With xlApp
.Application.Sheets("qrpt_DR").Select
.Application.Cells.Select
.Application.Cells.Font.Name = "Century Gothic"
.Application.Cells.Font.Size = 10
.Application.Selection.Columns.AutoFit
.Application.Selection.Rows.AutoFit
.Application.ActiveWorkbook.Save
.Application.ActiveWorkbook.Close
.Quit
End With
Set xlApp = Nothing
Set xlSheet = Nothing
Exit_ModifyExportedExcelFileFormats:
Exit Sub
Err_ModifyExportedExcelFileFormats:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_ModifyExportedExcelFileFormats
End Sub
***************************
However, I get the error message:
-214741851 - Method 'Save' of Object '_Workbook' failed. I have not been able to find any information on the error message and how to get around it.