query to excel (1 Viewer)

kitty77

Registered User.
Local time
Today, 07:01
Joined
May 27, 2019
Messages
710
How do I run a query then have it create a excel file? Macro? VBA?
Without doing it manually?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:01
Joined
Oct 29, 2018
Messages
21,454
Hi. You should be able to use either one, but I prefer to use VBA.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:01
Joined
Aug 30, 2003
Messages
36,124
TransferSpreadsheet and OutputTo are the two most common/easiest methods. I use VBA but I think both are macro actions too.
 

kitty77

Registered User.
Local time
Today, 07:01
Joined
May 27, 2019
Messages
710
I'm using this, it works but it exports it as if you checked off to export with formatting. Can I change that?

DoCmd.OutputTo ObjectType:=acOutputQuery, ObjectName:="sales", OutputFormat:=acFormatXLS, Outputfile:="C:\aaa\test.xls"
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:01
Joined
Oct 29, 2018
Messages
21,454
I'm using this, it works but it exports it as if you checked off to export with formatting. Can I change that?

DoCmd.OutputTo ObjectType:=acOutputQuery, ObjectName:="sales", OutputFormat:=acFormatXLS, Outputfile:="C:\aaa\test.xls"

Try TransferSpreadheet. I think it doesn't format the data.
 

kitty77

Registered User.
Local time
Today, 07:01
Joined
May 27, 2019
Messages
710
Can you give me an example using mine?

Thanks...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:01
Joined
Oct 29, 2018
Messages
21,454
Can you give me an example using mine?

Thanks...
Code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "sales", "c:\aaa\test.xlsx", True
 

Users who are viewing this thread

Top Bottom