Docmd.Transferspreadsheet (2 Viewers)

Kingz

Member
Local time
Today, 02:47
Joined
Mar 19, 2024
Messages
38
Hi, I was wondering if I could rename an excel export. I'm actually surprised there isn't a "sheetname". I guess I could rename my query table but I don't want to, die to organisational reasons. Here is my statement:

StrTable="3_boxphase"
Docmd.TransferSpreadsheet Transfertype:=acexport, spreadsheettype=acspreadtypeexcel12xml, table name:= strTable filename:=strdestpath, hasfieldnames:=True

So strTable is a query name, but I would like to call the sheet "Box"
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:47
Joined
Sep 21, 2011
Messages
14,336
Not with that command. You could edit the sheet afterwards and rename?
 

Kingz

Member
Local time
Today, 02:47
Joined
Mar 19, 2024
Messages
38
Ah, I've found it... It's "Range" oddly enough ;) Thanks
 

ebs17

Well-known member
Local time
Today, 02:47
Joined
Feb 7, 2020
Messages
1,949
I guess I could rename my query table but I don't want to, die to organisational reasons
Saved under new name (CreateQueryDef, ...):
Code:
SELECT * FROM ExistingName
Can your organization cope with something like that?
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:47
Joined
Sep 21, 2011
Messages
14,336
Ah, I've found it... It's "Range" oddly enough ;) Thanks
No it is not. :(

From https://learn.microsoft.com/en-us/office/vba/api/access.docmd.transferspreadsheet


RangeOptionalVariantA string expression that's a valid range of cells or the name of a range in the spreadsheet. This argument applies only to importing. Leave this argument blank to import the entire spreadsheet. When you export to a spreadsheet, you must leave this argument blank. If you enter a range, the export will fail.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:47
Joined
Oct 29, 2018
Messages
21,485
Ah, I've found it... It's "Range" oddly enough ;) Thanks
It's one of those things you'll find out only by accident. But as the documentation shows, it's not guaranteed to work forever. Cheers!
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:47
Joined
Feb 19, 2002
Messages
43,328
A safer solution is to create a query that has the name you want for the Worksheet. That query then selects the data query and is only used for exporting.
 

Kingz

Member
Local time
Today, 02:47
Joined
Mar 19, 2024
Messages
38
No it is not. :(

From https://learn.microsoft.com/en-us/office/vba/api/access.docmd.transferspreadsheet


RangeOptionalVariantA string expression that's a valid range of cells or the name of a range in the spreadsheet. This argument applies only to importing. Leave this argument blank to import the entire spreadsheet. When you export to a spreadsheet, you must leave this argument blank. If you enter a range, the export will fail.
It works for me! I read it somewhere and tried it. I think the main purpose is give you a chance to say exactly where, say, "Main!B2:c7", but just the name seems to change the sheet name from the table table to that.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:47
Joined
Feb 19, 2002
Messages
43,328
It works for me!
When the documentation says that it doesn't work, you should be worried, very worried rather than think you've put something over on Access.
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:47
Joined
Sep 21, 2011
Messages
14,336
Care to share how you did it?
I just tried with 2019
and get
1713645214235.png

and not even trying a range?


1713645163605.png
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:47
Joined
Sep 21, 2011
Messages
14,336
Best I can see is that the range parameter will at least allow a sheetname on export, but not an actual range?
 

Users who are viewing this thread

Top Bottom