Excel Automation

G

Guest

Hi

I've written some code which creates an Excel spreadsheet, enters some text, does some formatting, then saves and closes it. It all runs without any errors but if I try and open the spreadsheet I just get the header bar. If I close Access and then try I can open the spreadsheet without any problems. This is the code:

Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

Set oExcel = CreateObject("Excel.application")
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.Worksheets(1)

....... formatting

oBook.SaveAs "D:\My Documents\Databases\Surveys\test.xls."
oExcel.Quit

Any ideas?

Karen
 
N

Naresh Nichani MVP

Hi:

Can you try a -

oExcel.Visible = True

Regards,

Naresh Nichani
Microsoft Access MVP

Karen said:
Hi

I've written some code which creates an Excel spreadsheet, enters some
text, does some formatting, then saves and closes it. It all runs without
any errors but if I try and open the spreadsheet I just get the header bar.
If I close Access and then try I can open the spreadsheet without any
problems. This is the code:
 
G

Guest

This seems too simple, but it might be it.

Whenever I do the command like:
oBook.SaveAs filename
I then do
oBook.Close
Set oBook = Nothing
Set oSheet = Nothing
Set oExcel = Nothing

Not sure if that is overkill, but you might try it and see
if it works better.

Carolyn
-----Original Message-----
Hi

I've written some code which creates an Excel
spreadsheet, enters some text, does some formatting, then
saves and closes it. It all runs without any errors but
if I try and open the spreadsheet I just get the header
bar. If I close Access and then try I can open the
spreadsheet without any problems. This is the code:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top