View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Worksheets not visible in Excel XP

John,

First of all if there is no existing Excel application running then
your code will fail at the GetObject line.
One way to get around that is to create a new instance of the App...
Set xlApp = New.Excel.Application
The new app will not be visible, but if you need to see it then..
xlApp.Visible = True

However, to answer you questions try...

Set wkb = xlApp.Workbooks.Add
Set wks = wkb.Worksheets(1)

I don't believe you need to specify the number of sheets in the
new app, as Excel will not create a workbook without at least one
sheet in it.

Also, I would set the worksheet and workbook objects to nothing
before quitting the application.

Regards,
Jim Cone
San Francisco, USA


wrote in message oups.com...
I wrote the following code in Access to create an Excel spreadsheet
output. In Excel 2000 it works fine. When I put it on Excel XP, the
spreadsheet is not visible and I can't seem to find a way to make it
visible. What am I missing?

' Setup Excel Spreadsheet
Dim xlApp As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
Const XL_NOTRUNNING As Long = 429
Set xlApp = GetObject(, "excel.application")
Excel.Application.SheetsInNewWorkbook = 1
Set wkb = Workbooks.Add
Set wks = Worksheets(1)

... bunch of cell writes ...

' Save the spreadsheet
sFileName = Me!tFileName
wkb.SaveAs sFileName

Exit_WriteToExcel:
wkb.Close
xlApp.Quit
Set wks = Nothing
Set wkb = Nothing
Set xlApp = Nothing
Set rs = Nothing
Set db = Nothing
Exit Sub

Thanks,
John