Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I open an existing Excel file via a button in Access?

Status
Not open for further replies.

Fltsimtestguy

Technical User
Mar 20, 2003
4
US
I created a button that obviously will "Run Application" and included a dlgCommon to bring up the Open File but Excel will not open with the selected file. Is there a reasonable way to have Excel open a selected file when the dialog box is displayed?
 
The following is code to open an Excel File from VBA. You would just need to substitute strString with the file name and path you get from the dlg control.

Sub mOpenExcel()
Dim appExcel As New Excel.Application
Dim strPath As String

strPath = "C:\Test\Test.xls"

appExcel.Visible = True
appExcel.Workbooks.Open strPath

Set appExcel = Nothing
End Sub

There are two ways to write error-free programs; only the third one works.
 
For an alternative, have a look at my FAQ:FAQ705-1971

copy the code into a module, then call it with:

fHandleFile("C:\accesstest.xls",WIN_MAX) and it will open the file in Excel.
You don't even need to worry about where Excel is installed on the machine as the code does all the work for you.

hth

Ben ----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top