473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to export an unsaved query to a new excel workbook?

I would like to generate the SQL text for data to export to an excel workbook. Further, I would like the workbook to have no saved location - just a new workbook (the default "book1", "book2"...). Lastly, the format of the data (pivot table, datasheet..) should also be optional.

I know access must be capable of this, because pushing the "Export to excel" button does exactly what I'm looking for, with any active query or table. Is there any way to harness the automation of the "Export to Excel" button through VB?

Everywhere I look seems only to have ways to export an existing query to an existing workbook.
Mar 10 '11 #1

✓ answered by NeoPa

This would not be remotely trivial.

I could only envisage doing this through Excel Automation (See Application Automation) using a process whereby you run the unsaved query; copy the results to the Clipboard; Open Excel and a new workbook within it; Paste those same results into the ne workbook; Leave the application open and visible. Not for the feint-hearted though.

3 2800
NeoPa
32,556 Expert Mod 16PB
This would not be remotely trivial.

I could only envisage doing this through Excel Automation (See Application Automation) using a process whereby you run the unsaved query; copy the results to the Clipboard; Open Excel and a new workbook within it; Paste those same results into the ne workbook; Leave the application open and visible. Not for the feint-hearted though.
Mar 11 '11 #2
that's actually what i'm using now, but it's a lot slower than just pushing the "Export to excel" button you see when you have a query, and I can't make the excel display the data as a pivot table, because I'm not all that familiar with excel vb. I would just tell people to use access's own "Export to Excel" button, but I don't want to display the query, and I'd rather have the export button on a form anyway.

is there a way to open a query but not show it, and then call the export to excel command, something from the "DoCmd.DoMenuItem" thing?
Mar 11 '11 #3
NeoPa
32,556 Expert Mod 16PB
If there were (and frankly it's something I never do so I'm really not 100% sure) then I would expect to find it as a flavour of DoCmd.RunCommand(Command). I looked in the list for you under Excel; Analyse; Export; but all I could find were the following Commands. Unfortunately there is no specific help for each Command so you may want to experiment :
  1. acCmdOutputToExcel
  2. acCmdPivotTableExportToExcel
  3. acCmdExport
Not much I know, but I have the feeling that was bolted on at some point with a view to providing an facility for an operator specifically, rather than for use in code. Who knows though? Maybe worth looking at these at least.
Mar 11 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jonny | last post by:
Hello, I have created a button on my form which when pressed does the following : 1) Run a pre-defined Macro, which is picking up a query and running my data to excel. However, I need the...
7
by: Pierre | last post by:
Hi, Tryin to use this method : MyExcelObject.Application.ActiveWorkBook.set_Colors(int index, object RHS). But really don't know what this RHS is ? Any ideas ? Thks for help
4
by: Tomek | last post by:
Hi, How could I export data from table or query to excel file in VB.NET? Thanks in advance, Tomek
0
by: Tony2299 | last post by:
How to export data using ASP to excel workbook (with multiple worksheets)? I created an excel workbook with 5 worksheets and each one has a name range. Using asp I insert data to individual...
5
by: Simon | last post by:
Dear reader, With the export command you can export a query to Excel. By activate this command a form pop's up with the following text:
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
10
by: afromanam | last post by:
Regards, Please help What I'm trying to do is this: (and I can't use reports since I must export to Excel) I export some queries to different tabs in an excel workbook I then loop through...
3
habby0123
by: habby0123 | last post by:
I am trying to export data to Excel from a query in Access. There is a unique "Sales Region ID" and various "Territory#'s" for each Region. I would like one excel workbook for each region, and a...
11
by: CarrieR | last post by:
Hi, I thought this was a simple issue, but apparently it's not. I need to export the contents of about 30 queries, each into a specific sheet, and cell range, of an existing Excel workbook. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.