Save Access report to specific Excel Worksheet 
Author Message
 Save Access report to specific Excel Worksheet

I have a P&L report in Access97 which includes 5 subreports: SALES,
COGS, R&D, S&M, G&A.  I am trying to export the results from each
subreport to Excel, but have the SALES subreport saved to Sheet1 of my
Excel workbook, COGS saved to Sheet2, and so on.

I have can save my report as an Excel workbook, but not to a specific
sheet in that workbook.

The code that I have developed so far is as follows:

Public Sub ExcelSales()

Dim objXL As New Excel.Application

    objXL.Visible = True
    objXL.Workbooks.Open "H:\Application Development\Amgen\P & L
Template.xls"
    objXL.Windows(1).Visible = True
    objXL.Worksheets(1).Range("A1:G25").Clear
    objXL.Worksheets(2).Range("A1:G25").Clear
    objXL.Worksheets(3).Range("A1:G25").Clear
    objXL.Worksheets(4).Range("A1:G25").Clear
    objXL.Worksheets(5).Range("A1:G25").Clear

    objXL.Worksheets(1).Activate
    DoCmd.SelectObject acReport, "srptSales", True
    ??? DoCmd.RunCommand acCmdSaveAs ???
         ***THIS IS WHERE I AM AT A LOSS***

    objXL.Workbooks(1).Close SaveChanges:=True

    objXL.Quit
    Set objXL = Nothing

End Sub

If it is not possible to "push" the report from Access to Excel, does
anyone have code to "pull" the report into Excel from Access?

--
TIA,
Randy Shore
Data Design
805.494.3439

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sun, 05 Jan 2003 03:00:00 GMT  
 Save Access report to specific Excel Worksheet
Randy:

Access has no ability to export to a specific worksheet using its standard
functions like transfer spreadsheet.  To accomplish what you are trying to
do, what you need to do is to attach (link) each spreadsheet page from your
workbook to the Access db, and then run an append query based on your
subreport's underlying queries to append the data to a target spreadsheet.
To attach a specific spreadsheet in the workbook, you'd use code like:

Dim Cdb as Database
Dim tmpTableDef as TableDef
Set Cdb = CurrentDb
Set tmpTableDef = Cdb.CreateTableDef("MyTempXLSheet1")
tmpTableDef.Connect = "Excel 5.0;HDR=NO;DATABASE=" & strTargetXLFilePath
tmpTableDef.SourceTableName = "XLWorksheet1Name"

then run an append query to the worksheet and delete the table def.

HTH
--
Steve Arbaugh
ATTAC Consulting Group
http://ourworld.compuserve.com/homepages/attac-cg/acgsoft.htm



Quote:
> I have a P&L report in Access97 which includes 5 subreports: SALES,
> COGS, R&D, S&M, G&A.  I am trying to export the results from each
> subreport to Excel, but have the SALES subreport saved to Sheet1 of my
> Excel workbook, COGS saved to Sheet2, and so on.

> I have can save my report as an Excel workbook, but not to a specific
> sheet in that workbook.

> The code that I have developed so far is as follows:

> Public Sub ExcelSales()

> Dim objXL As New Excel.Application

>     objXL.Visible = True
>     objXL.Workbooks.Open "H:\Application Development\Amgen\P & L
> Template.xls"
>     objXL.Windows(1).Visible = True
>     objXL.Worksheets(1).Range("A1:G25").Clear
>     objXL.Worksheets(2).Range("A1:G25").Clear
>     objXL.Worksheets(3).Range("A1:G25").Clear
>     objXL.Worksheets(4).Range("A1:G25").Clear
>     objXL.Worksheets(5).Range("A1:G25").Clear

>     objXL.Worksheets(1).Activate
>     DoCmd.SelectObject acReport, "srptSales", True
>     ??? DoCmd.RunCommand acCmdSaveAs ???
>          ***THIS IS WHERE I AM AT A LOSS***

>     objXL.Workbooks(1).Close SaveChanges:=True

>     objXL.Quit
>     Set objXL = Nothing

> End Sub

> If it is not possible to "push" the report from Access to Excel, does
> anyone have code to "pull" the report into Excel from Access?

> --
> TIA,
> Randy Shore
> Data Design
> 805.494.3439



Sun, 12 Jan 2003 03:00:00 GMT  
 Save Access report to specific Excel Worksheet
Thanks for your reply, Steve.

What I ended up doing was to export my 5 different sub-report results
to 5 new workbooks, and then using automation from Access, selected the
data in each temp workbook and pasted it onto the appropriate worksheet
of the actual workbook.  It uses alot of resources as I end up with 6
instances of excel open at one time (actually, 6 different workbooks,)
but at least it works consistently.

--
Regards,
Randy Shore
Data Design
805.494.3439

Sent via Deja.com http://www.deja.com/
Before you buy.



Sat, 18 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. open excel to specific worksheet

2. Saving Excel Worksheet in DB as OLE Object

3. Saving an Excel Worksheet from code running in Word

4. Saving table to excel worksheet.

5. Saving data into Excel Worksheet

6. Saving records to Excel worksheet

7. Saving data into Excel worksheet

8. Save a Worksheet in Excel to a Master Workbook

9. Save Worksheet objects in Access

10. Enumerating Excel worksheets within Access

11. Exporting Access tbl to Excel - Worksheet Names

12. Access/VBA: Creating New Excel Worksheets?

 

 
Powered by phpBB® Forum Software