Export table data from access to excel with a command button

rplohocky

Active Member
Joined
Sep 25, 2005
Messages
292
Office Version
  1. 365
Platform
  1. Windows
I've searched the net completely looking for a way to export my table data into a preexisting excel workbook without success. I would like to have a command button on a form that when clicked, will copy a table of data in to a "pre-named existing" workbook and a specific worksheet.

Any help would be great, thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Thanks but not really. I am brand new at Access and don't know exactly where and how to insert the code into VBA. I have written many macros in excel but only a couple in Access. Also the code they are showing does not have an option to select a specific page to place the data. Currently I have a macro that will export the data into a blank workbook and name the sheet but I am wanting to have different buttons create different exports of data. Such as one tab would be for "completed" and another tab would be "not completed". I built the macro using the macro function in Access.
 
Upvote 0
In Welschgasman's link, this is the code you should be using as an example.

Code:
Public Sub xportQuery()
    DoCmd.TransferSpreadsheet TransferType:=acExport, SpreadsheetType:=acSpreadsheetTypeExcel9, TableName:="Query1", FileName:="C:\test\template.xlsx", Range:="exportRange"
End Sub
 
Upvote 0
How you implement it is up to you.
The most basic would be the Click event of a button as you mentioned.
Change the names in the code to match.

alansdman has pointed out what code on that page you need.
If you read the page, it will explain the parameters as well.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,044
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top