473,624 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Export to Excel multiple existing sheets

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.TransferS preadsheet acExport, 8, "Table1", "D:\Test.xl s", True


Dim xlObj
Set xlObj = CreateObject("e xcel.applicatio n")
xlObj.Workbooks .Open "D:\Template.xl s"
xlObj.activewor kbook.saveas "D:\Date.xl s"
xlObj.Workbooks .Open "D:\Test.xl s"
xlObj.activeshe et.cells.select
xlObj.activeshe et.cells.Copy
xlObj.Workbooks ("Date.xls").Ac tivate
xlObj.activewor kbook.sheets(1) .range("a1").se lect
xlObj.activeshe et.paste
xlObj.activeshe et.Visible = False
xlObj.activewor kbook.Save
xlObj.activewor kbook.Close
xlObj.activewor kbook.Save
xlObj.activewor kbook.Close
xlObj.Quit
Set xlObj = Nothing
MsgBox "Report exported successfully"
Dim stAppName As String

stAppName = "Excel.exe D:\date.xls"
Call Shell(stAppName , 1)

End Sub
This works fine, but just with one table. When I try to export another
table with the same code to
xlObj.activewor kbook.sheets(2) .range("a1").se lect, then I get an error
about subcscipt out of range...
I am wondering if I should create a temp.xls file on the second table
instead, and have an access macro do the copying between the 2
workbooks. I am still unable to get this for the past 3 days.

Please help !
Cheers!
Sunny

Nov 13 '05 #1
4 18236

<su**********@g mail.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
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.TransferS preadsheet acExport, 8, "Table1", "D:\Test.xl s", True


Dim xlObj
Set xlObj = CreateObject("e xcel.applicatio n")
xlObj.Workbooks .Open "D:\Template.xl s"
xlObj.activewor kbook.saveas "D:\Date.xl s"
xlObj.Workbooks .Open "D:\Test.xl s"
xlObj.activeshe et.cells.select
xlObj.activeshe et.cells.Copy
xlObj.Workbooks ("Date.xls").Ac tivate
xlObj.activewor kbook.sheets(1) .range("a1").se lect
xlObj.activeshe et.paste
xlObj.activeshe et.Visible = False
xlObj.activewor kbook.Save
xlObj.activewor kbook.Close
xlObj.activewor kbook.Save
xlObj.activewor kbook.Close
xlObj.Quit
Set xlObj = Nothing
MsgBox "Report exported successfully"
Dim stAppName As String

stAppName = "Excel.exe D:\date.xls"
Call Shell(stAppName , 1)

End Sub
This works fine, but just with one table. When I try to export another
table with the same code to
xlObj.activewor kbook.sheets(2) .range("a1").se lect, then I get an error
about subcscipt out of range...
I am wondering if I should create a temp.xls file on the second table
instead, and have an access macro do the copying between the 2
workbooks. I am still unable to get this for the past 3 days.

Please help !
Cheers!
Sunny


This is, no doubt, another one of those cases with lots of different ways to
do it.
I start with a template workbook, similar to the way you are doing it. I do
the TransferSpreads heet directly into the copy of the template.

DoCmd.TransferS preadsheet acExport, 8, "Table1", "D:\date.xl s", True
DoCmd.TransferS preadsheet acExport, 8, "Table2", "D:\date.xl s", True

You'll end up with 2 new worksheets in that workbook, one named Table1, the
other Table2.

Address the individual worksheets with:
Set xlObj = GetObject("D:\d ate.xls")
With xlObj.Applicati on
.Sheets("Table1 ").Select
.Range("a1:b2") .Select
.Selection.Copy
.Sheets("Destin ation").Select
.Range("a1").Se lect
.ActiveSheet.Pa ste
.Sheets("Table2 ").Select
.etc, etc
You should get the idea at this point. You might want to delete, move or
rename the new worksheets. Set fonts, colors, column widths and borders. You
can also turn on autofilters and freeze panes.

HTH,
Randy Harris

Nov 13 '05 #2
Thanks..But the problem is that I have already existing sheets on that
file, which are referenced to the exported sheet with a formula...I
might do better with an excel macro which will copy data from the
exported table data...

Cheers!
Sunny

Nov 13 '05 #3

<su**********@g mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Thanks..But the problem is that I have already existing sheets on that
file, which are referenced to the exported sheet with a formula...I
might do better with an excel macro which will copy data from the
exported table data...

Cheers!
Sunny


To me it seems logical to simply import the data to a new sheet and copy it
over to the existing sheet. But, suit yourself.

Nov 13 '05 #4

Randy Harris wrote:
<su**********@g mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Thanks..But the problem is that I have already existing sheets on that
file, which are referenced to the exported sheet with a formula...I
might do better with an excel macro which will copy data from the
exported table data...

Cheers!
Sunny


To me it seems logical to simply import the data to a new sheet and copy it
over to the existing sheet. But, suit yourself.


Yes. i have written a macro which will import into the required sheet.
I can run the macro through access.

Thanks for the help!

Cheers
Sunny

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2590
by: ABC | last post by:
What methods can export excel file from stored procedure with parameters which input from web form?
1
3046
by: panku007 | last post by:
hi All, I wanted to export excel data into ms word document through java coding.So please send me reply,according to my question. thanks
2
1853
by: tbenchakroune | last post by:
How can I export Excel spreadsheets to Access db? Thanks, T.
1
2852
by: san1014 | last post by:
Hi How to import and export excel data into oracle database using java. Thank you
1
6186
by: CF FAN | last post by:
Can Report Builder Export Excel Files with multiple Sheets How can I create a report that it can export in excel by multiple
3
3034
by: minhtran | last post by:
Hi all Anyone has any idea how to get a Excel header column in VB.NET. Please, help me. Thank you so much in advance
0
2502
by: Dubois | last post by:
Bonjour Lorsque je lance un export excel au travert d'une page en ASP.NET C#, cela fonctionne sur la machine de développement, par contre, sur le serveur de production j'ai l'erreur suivante : ***************** La récupération de la fabrique de classe COM pour le composant avec le CLSID {00024500-0000-0000-C000-000000000046} a échoué en raison de l'erreur suivante : 80070005.
4
2397
by: fjm | last post by:
Hello everyone. I’d like to know how to handle multiple style sheets. I have css tabs that have a style sheet and then I also have a separate style sheet for the content that goes inside the tab. The problem I am running into is that the tab style sheet uses attributes in the html and body and so does the content style sheet. Each one is specific to its content. The tab style sheet seems to take precedence over the content style sheet because...
3
4064
by: prashantdixit | last post by:
Hi, I am trying to export excel data to text file in a particular format. The Format for each ROW of Excel is like IMAN_ROOT/bin/import_file -f=<Column A> -type=<Column B> -d=<Column C> -ref=<Column D> -vb -log=<Column E> Every Row of the excel should export in text with this format.
0
8234
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7158
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.