473,395 Members | 1,652 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,395 software developers and data experts.

Export Queries to Same Excel File, but Different WorkSheets

Hey everybody.

I have Access set up using VBA to run a bunch of queries automatically, and then export the results into Excel. The only problem is, I want each query to be exported to the same Excel File, but different worksheet.

What happens now is that a new Excel file is opened for each query (with the same name, as read-only) and then the data is imported into the correct worksheet number. I just need to figure out a way to have it all pasted into the same file!

The code that is responsible for this part is here I believe:

Expand|Select|Wrap|Line Numbers
  1. WorksheetToPlace = "Sheet" & WorksheetNumber
  2.     Set App = CreateObject("Excel.Application") 'This opens excel application windows
  3.     App.Visible = True
  4.     Set File = App.Workbooks.Open("C:\Sessions\NumberOfSessions.xls") 'This opens your particular excel file (or workbook)
  5.     Set ws = File.Worksheets(WorksheetToPlace) 'This opens your sheet that you want to write to
  6.     ws.Activate
I am using other people's code to make my application, and just modifying components. Using Access/Excel 2003

Thanks for your time!
Jul 31 '07 #1
4 10483
Hey everybody.

I have Access set up using VBA to run a bunch of queries automatically, and then export the results into Excel. The only problem is, I want each query to be exported to the same Excel File, but different worksheet.

What happens now is that a new Excel file is opened for each query (with the same name, as read-only) and then the data is imported into the correct worksheet number. I just need to figure out a way to have it all pasted into the same file!

The code that is responsible for this part is here I believe:

Expand|Select|Wrap|Line Numbers
  1. WorksheetToPlace = "Sheet" & WorksheetNumber
  2.     Set App = CreateObject("Excel.Application") 'This opens excel application windows
  3.     App.Visible = True
  4.     Set File = App.Workbooks.Open("C:\Sessions\NumberOfSessions.xls") 'This opens your particular excel file (or workbook)
  5.     Set ws = File.Worksheets(WorksheetToPlace) 'This opens your sheet that you want to write to
  6.     ws.Activate
I am using other people's code to make my application, and just modifying components. Using Access/Excel 2003

Thanks for your time!

Go to macro in Access.Create a new macro. Click on the drop down for "TransferSpreadsheets" under Actions. Fill in the information like: Transfer Type, Spreadsheet Type, query/ Table name, etc. You can export all of your queries into one excel worksheet.
Jul 31 '07 #2
I don't see how you can do it with out VBA code.

The post above I do not belive will work. I could be wrong. I hope it is right and it will solve all you problems.
I think you can only export one table or query at a time and you will still end up with Multiple workbooks.

------

I don't know if this is the route you want to go, but it may help.

I run the SQL from Excel and update muiltple formated worksheets daily.

You could try this:
1. In Excel go to the Data Menu / Import External Data / Import data.

2. Find you DB, Connect to it.

3. You can select you query right there from the list.

OR (very optional)
if after you select one (table or query) you can "Edit Query"
under "Command Text" you can Select SQL instead of TABLE and just paste youe SQL code there.

NOTE: you might want ot check out the "Properties" button to see options. Mostly post import formating.

Either way it ends up in Excel and you can format it and make it look nice.

In the future you can right click on the data and select "Refresh Data" (also under the Data Menu).

I added a Refresh All button to my Menu.
(Tool/Custonize/ In the Command Box select Data and Scroll down you will see it and drag it to you toolbar)

I don't know I like this way. You can format how ever you want and it keeps em from having hundreds of queries in my DB.

Good Luck

-- Boxcar
Jul 31 '07 #3
I forgot you are using VBA to run the queries automatically.

So I doubt my way is how you want to go. You may want to consider it.

Sorry :(

-- Box
Jul 31 '07 #4
Hi Chris Gilpin,

Have you found a way to solve your initial problem?
i.e. Exporting a bunch of queries into 1 Excel file with a "tab" for each query?

I have tried the solution that "eskelies" offered and have found that there are 2 issues:

- you require the excel spreadsheet to exist already
- the file just appends the extra tabs

Please advise.

regards
Jane
Aug 23 '07 #5

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

Similar topics

4
by: Anthony Cuttitta Jr. | last post by:
I'm working on some procedures where Access queries are exported to Excel, and then later on, those same workbooks are openned, and I need to target a specific original sheet. Sometimes there will...
4
by: sunilkeswani | last post by:
I need help with exporting data from 2 access tables, into 2 existing spreadsheets in a single Excel file. Currently, I am using this code: DoCmd.TransferSpreadsheet acExport, 8, "Table1",...
6
by: Elena | last post by:
I'm trying to export data to an Excel worksheet. I can export the data in the cell values perfectly. I need the code to change a header and footer for the worksheet, not for the columns. Is...
4
by: paul.chae | last post by:
I have a table in Access with about 3000 records. There are ~60 unique values in the ID field for the 3000 records. What I would like to do is automatically generate multiple Excel worksheets...
7
by: Vanessa | last post by:
hi Everyone, I have two questions on exporting data to Excel using ASP (w/o converting formatted excel file into web page and then plug in the dynamic data): 1. Can we export data into...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
0
by: sandervanee | last post by:
Hello, I am trying to export several Access 2003 select queries to Excel 2003 using an Access macro. I'm using the macro command "TransferSpreadsheet" to export the queries. This going quit well,...
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...
1
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.