Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to close Excel form using codes in Access?

Status
Not open for further replies.

Doraemon

IS-IT--Management
Sep 12, 2003
31
HK
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:
&quot;xlobj.Workbooks.SaveAs strFile&quot;
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.
 
I found my answer from the following thread:
thread705-629861

Thank you for your attention.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top