Hi,
I have a form in Access 2010 on which I would like to include a button which could clear an excelsheet save it and quit. I wrote the following code into the code builder of a command button.
However, it shows Run-time error'424': Object required when I click on the button. When I open the Debugger it highlights Sheet1.Cells.Cl earContents
Please help me with this
I have a form in Access 2010 on which I would like to include a button which could clear an excelsheet save it and quit. I wrote the following code into the code builder of a command button.
Code:
Private Sub Command10_Click()
'Need to declare outside of any Sub
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
'open excel application
Set xlApp = New Excel.Application
'Open excel workbook
Set xlWB = xlApp.Workbooks.Open(FileName:="C:\Users\user\Documents\Excel sheets\temptab.xlsm")
'do your code here
Sheet1.Cells.ClearContents
ThisWorkbook.Save
'Close workbook (optional)
xlWB.Close
'Quit excel (automatically closes all workbooks)
xlApp.Quit
'Clean up memory (you must do this)
Set xlWB = Nothing
Set xlApp = Nothing
End Sub
However, it shows Run-time error'424': Object required when I click on the button. When I open the Debugger it highlights Sheet1.Cells.Cl earContents
Please help me with this
Comment