Change tab name in export to excel

mark1080p

New Member
Joined
Jun 21, 2011
Messages
18
Hi,

I have a quick question

I have a list of reports that are saved in a shared location. However The person I report to, wants all the files to have the same tab name.

Please see below, I have trimmed the code to give you the jist of what i am doing...so for argument sake say I have a few queries built called Report 1, Report 2, Report 3 etc...

I have the following/similar code in all my access form buttons
Private Sub Command0_Click()
DoCmd.OutputTo acOutputQuery, "report1", acFormatXLS, "C:\Users\Mark\Access\report1.xls", False
DoCmd.OutputTo acOutputQuery, "report2", acFormatXLS, "C:\Users\Mark\Access\report2.xls", False
DoCmd.OutputTo acOutputQuery, "report3", acFormatXLS, "C:\Users\Mark\Access\report3.xls", False
End Sub

which will run the reports, but the tab name is also called "report1,2,3 respectively" same as the queries. Can anyone advise what vb code I can add to change the tab name to say "test" for example. so when I reun Report 1, 2, 3 etc all the tabs are called "Test"

I read that it can be done with transfer spreadsheet below, but still cant get the code work.

Private Sub Command1_Click()
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "report1", "C:\Users\Mark\Access\report1.xls", False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "report2", "C:\Users\Mark\Access\report2.xls", False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "report3", "C:\Users\Mark\Access\report3.xls", False
End Sub

I tried to add the following piece of code
sheets("report1")="test"
but to no avail.

I would change the query name, but I have 10 other similar vbcodes like above that I run, so cant name all the queries/tables with the same name.

Hope someone can help
 
Last edited:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
It's not possible to do I'm afraid, unless you use some other method to export the data.
 
Upvote 0
Alan

I thought you could do something like that but wasn't sure.

In fact when I think about it I definitely used that in the past.
 
Upvote 0
Brilliant!

Many thanks Alan - It works a treat.

Only issue is to work out how to put data back to HH:MM:SS
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,691
Members
452,938
Latest member
babeneker

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