473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Clearing contents of en excel sheet from a button in access form

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.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Command10_Click()
  2. 'Need to declare outside of any Sub
  3. Dim xlApp As Excel.Application
  4. Dim xlWB As Excel.Workbook
  5.  
  6.  'open excel application
  7.  Set xlApp = New Excel.Application
  8.  'Open excel workbook
  9.  Set xlWB = xlApp.Workbooks.Open(FileName:="C:\Users\user\Documents\Excel sheets\temptab.xlsm")
  10.     'do your code here
  11. Sheet1.Cells.ClearContents
  12. ThisWorkbook.Save
  13.  
  14.  'Close workbook (optional)
  15. xlWB.Close
  16.  'Quit excel (automatically closes all workbooks)
  17. xlApp.Quit
  18.  'Clean up memory (you must do this)
  19.  Set xlWB = Nothing
  20.  Set xlApp = Nothing
  21. 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.ClearContents

Please help me with this
Jul 13 '10 #1
1 1537
@ragnarok24
I was searching for reasons for runtime error 424 and found that this problem may occur when the Data Access Object library is not properly referenced.
Is there reference library I might be missing?
Jul 14 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then...
2
by: info | last post by:
I can successfully open a recordset based upon an Excel sheet in Access, but I can't work out how to copy all the records to an Access table. Any pointers?
1
by: Infinito | last post by:
It's possible to encapsulate Excel in a Access Form so that I can write on the EXCEL sheet? Thanks
5
Zerin
by: Zerin | last post by:
I have to develop a database in access and VB 2005 will be in front view. Some results are send to this software in .csv format and .jpg format and I have to store it in the database.Now, for .csv...
0
by: jj | last post by:
I'm going mad! I'm exporting a query to excel, and afterwards calculating a field, and a sum of all fields in Excel from a sub procedure in a Module in Access. First I used ...
1
by: gpgp | last post by:
I have a excel macro like this: 1. Range("C2").Select Range(Selection, Selection.End(xlDown)).Select Selection.Replace What:=".", Replacement:="/", LookAt:=xlPart, _ ...
2
by: saddist | last post by:
Hello, I have and excel sheet with fields: Name | Surname | Dept. When I execute the following code, it imports 16 empty rows + filled ones DoCmd.TransferSpreadsheet acImport = 0,...
3
by: inepu | last post by:
I have some excel sheets that I would like to manage in access. I've created the access tables and relationships; the excel sheet is only one table and with duplicate data, I'd like to make sure that...
0
by: satenova | last post by:
Hello Friends, I am newbie when it comes to vb.net and i need to import excel sheet into access db using vb.net application. Here is the code i use for now to upload excel sheet and it works...
6
by: brunpam | last post by:
Hello, I'm somewhat new to Access and I'm trying to open an Excel file from an Acess form command button. The only problem is the Excel filename includes a date and the date changes on a weekly...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.