Exported Query Including Macro

bvbull200

New Member
Joined
Jul 29, 2013
Messages
24
I have a query in Access with a saved sequence for exporting to Excel. I want the Excel file to include a macro that I created saved to it. I'm going to be updating the file once a week or so.

The file will be accessed by a large number of people, most of which have a very basic knowledge of Excel, so saving the macro to everyone's personal workbook isn't really feasible.

Is it possible for the file outputted from Access to include a macro?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
No, but you can run the Excel macro inside Access.
the Access macro would be:
transferspreadsheet ....
RunCode FormatXL()

The code ,FormatXL ,would run the exact formatting in excel ,from Access.
 
Upvote 0
Why not create an Excel template workbook with the code in it and export from Access to that template/workbook?
 
Upvote 0
No, but you can run the Excel macro inside Access.
the Access macro would be:
transferspreadsheet ....
RunCode FormatXL()

The code ,FormatXL ,would run the exact formatting in excel ,from Access.

I'll look more in to this. I'm absolutely terrible with Access, so it'll take a little trial and error, but if it can be exported with the formatting already done, that's a good thing.

Why not create an Excel template workbook with the code in it and export from Access to that template/workbook?

This is a good idea, too. Whenever it exports to the workbook, I need to make sure that it overwrites everything that was already on it (except the macro, of course). I'll look further in to this.
 
Upvote 0
The template workbook should be totally blank, apart from the code of course and perhaps any 'pre-formatting' you might want.
 
Upvote 0
As ranman256 pointed out, the "transferspreadsheet" creates a new file each time.

I agree with Norie that using a true Excel template is the way to go.

This may help:[h=1]Save a workbook or worksheet as a template[/h]
In Microsoft Office Excel 2007 [and later], a template file (.xltx) can include data and formatting, and a macro-enabled template file (.xltm) can also include macros.


It will require some VBA code to use Office Automation to do what you want.
 
Upvote 0
As ranman256 pointed out, the "transferspreadsheet" creates a new file each time.

I agree with Norie that using a true Excel template is the way to go.

This may help:Save a workbook or worksheet as a template





It will require some VBA code to use Office Automation to do what you want.

The macro includes adding slicers. I feel like this changes things a little bit since it isn't strictly formatting that is being done.

I wonder what this will look like if the macro is run within Excel.
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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