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

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.TransferSpreadsheet acExport, 8, "Table1", "D:\Test.xls", True


Dim xlObj
Set xlObj = CreateObject("excel.application")
xlObj.Workbooks.Open "D:\Template.xls"
xlObj.activeworkbook.saveas "D:\Date.xls"
xlObj.Workbooks.Open "D:\Test.xls"
xlObj.activesheet.cells.select
xlObj.activesheet.cells.Copy
xlObj.Workbooks("Date.xls").Activate
xlObj.activeworkbook.sheets(1).range("a1").select
xlObj.activesheet.paste
xlObj.activesheet.Visible = False
xlObj.activeworkbook.Save
xlObj.activeworkbook.Close
xlObj.activeworkbook.Save
xlObj.activeworkbook.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.activeworkbook.sheets(2).range("a1").select, 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 18223

<su**********@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.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.TransferSpreadsheet acExport, 8, "Table1", "D:\Test.xls", True


Dim xlObj
Set xlObj = CreateObject("excel.application")
xlObj.Workbooks.Open "D:\Template.xls"
xlObj.activeworkbook.saveas "D:\Date.xls"
xlObj.Workbooks.Open "D:\Test.xls"
xlObj.activesheet.cells.select
xlObj.activesheet.cells.Copy
xlObj.Workbooks("Date.xls").Activate
xlObj.activeworkbook.sheets(1).range("a1").select
xlObj.activesheet.paste
xlObj.activesheet.Visible = False
xlObj.activeworkbook.Save
xlObj.activeworkbook.Close
xlObj.activeworkbook.Save
xlObj.activeworkbook.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.activeworkbook.sheets(2).range("a1").select, 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 TransferSpreadsheet directly into the copy of the template.

DoCmd.TransferSpreadsheet acExport, 8, "Table1", "D:\date.xls", True
DoCmd.TransferSpreadsheet acExport, 8, "Table2", "D:\date.xls", 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:\date.xls")
With xlObj.Application
.Sheets("Table1").Select
.Range("a1:b2").Select
.Selection.Copy
.Sheets("Destination").Select
.Range("a1").Select
.ActiveSheet.Paste
.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**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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
by: ABC | last post by:
What methods can export excel file from stored procedure with parameters which input from web form?
1
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
by: tbenchakroune | last post by:
How can I export Excel spreadsheets to Access db? Thanks, T.
1
by: san1014 | last post by:
Hi How to import and export excel data into oracle database using java. Thank you
1
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
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
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 : ...
4
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. ...
3
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>...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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.