How do I open an Excel spreadsheet from Access 2002?

  • Thread starter Thread starter Guest
  • Start date Start date
Here's a simplified method of what I use.

Dim xlApp As Variant
Dim xlBook As Variant
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\data\excel\somewb.xls")
xlApp.Application.Visible = True
Set xlApp = Nothing
Set xlBook = Nothing


--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| How do I open an Excel spreadsheet from Access 2002?
 
The below code works fine but you can do it much simpler. If you want to open
the Excel file by clicking a button called 'OpenExelFileBtn' then put this
code in the OnClick event:

Me.Controls("OpenExcelFileBtn").HyperlinkAddress = "C:\data\excel\somewb.xls"
......All done in 1 line

If you don't know the filename but are going to pick it up from a Text box
on the form

Me.Controls("OpenExcelFileBtn").HyperlinkAddress = " " ' Do this first to
make sure you don't carry something over from an invalid last try.

If Dir(Me("TextBoxFilename") & ".XLS") = "" then
MsgBox "File not found etc...."
Exit Sub
End IF
Me.Controls("OpenExcelFileBtn").HyperlinkAddress = Me("TextBoxFilename") &
".XLS"

Regards
Nigel
 
Cool, thanks Nigel!

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| The below code works fine but you can do it much simpler. If you want to
open
| the Excel file by clicking a button called 'OpenExelFileBtn' then put this
| code in the OnClick event:
|
| Me.Controls("OpenExcelFileBtn").HyperlinkAddress =
"C:\data\excel\somewb.xls"
| ......All done in 1 line
|
| If you don't know the filename but are going to pick it up from a Text box
| on the form
|
| Me.Controls("OpenExcelFileBtn").HyperlinkAddress = " " ' Do this first
to
| make sure you don't carry something over from an invalid last try.
|
| If Dir(Me("TextBoxFilename") & ".XLS") = "" then
| MsgBox "File not found etc...."
| Exit Sub
| End IF
| Me.Controls("OpenExcelFileBtn").HyperlinkAddress = Me("TextBoxFilename") &
| ".XLS"
|
| Regards
| Nigel
 
Back
Top