I would like to export data from Access to Excel, with some formatting done in Excel. When I run the following codes, two errors are found, in which I don't know how to correct them.
Private Sub cmd_export_Click()
Dim strFile As String
Dim xlobj As Object, strExcelFile As String
strExcelFile = "C:\temp\testing\Data.xls"
Set xlobj = CreateObject("excel.application"
xlobj.Application.Visible = True
With xlobj
.Workbooks.Open FileName:=strExcelFile
.Worksheets("Sheet1"
.Select
.Range("D3"
.Value = "Trial"
End With
strFile = "C:\temp\testing\Data2.xls"
xlobj.Workbooks.SaveAs strFile <--- Error1
xlobj.Workbooks.Close
xlobj.Close <--- Error2
Set xlobj = Nothing
End Sub
What I want to do is to CLOSE the Excel form after the formatting is done. However, the statement:
"xlobj.Workbooks.SaveAs strFile"
is failed and if omitted, a message box will pop up to ask user if they want to save the excel file, which is NOT what I want.
Thank you for your help in advance.
Private Sub cmd_export_Click()
Dim strFile As String
Dim xlobj As Object, strExcelFile As String
strExcelFile = "C:\temp\testing\Data.xls"
Set xlobj = CreateObject("excel.application"
xlobj.Application.Visible = True
With xlobj
.Workbooks.Open FileName:=strExcelFile
.Worksheets("Sheet1"
.Range("D3"
End With
strFile = "C:\temp\testing\Data2.xls"
xlobj.Workbooks.SaveAs strFile <--- Error1
xlobj.Workbooks.Close
xlobj.Close <--- Error2
Set xlobj = Nothing
End Sub
What I want to do is to CLOSE the Excel form after the formatting is done. However, the statement:
"xlobj.Workbooks.SaveAs strFile"
is failed and if omitted, a message box will pop up to ask user if they want to save the excel file, which is NOT what I want.
Thank you for your help in advance.