Open excel file within same directory as access database

iisjman07

Registered User.
Local time
Today, 14:58
Joined
Feb 21, 2011
Messages
10
Hi, I have an access database and an excel 2003 (.xls) file in the same folder. I want a button on the access database switchboard to open the excel file, but it wants a full file path. Due to certain circumstances this path may be subject to change, and I don't know how to refer to an external excel file within the same folder. Currently I have:

Code:
Private Sub Command60_Click()
    Dim objXLApp As Object
    Dim objXLBook As Object
    Set objXLApp = CreateObject("Excel.Application")
    Set objXLBook = objXLApp.Workbooks.Open("Quote_Builder.xls")
    objXLApp.Application.Visible = True
End Sub

Quote_Builder.xls is the file I'm trying to open, but if I don't put a path in the 'objXLApp.Workbooks.Open' command then it errors out saying it could not be found. Any help?
 
Look into CurrentProject.Path

Ah, thanks a lot. For anyone interested here's the final code:
Code:
Private Sub Command116_Click()
Dim objXLApp As Object
    Dim objXLBook As Object
    Set objXLApp = CreateObject("Excel.Application")
    Set objXLBook = objXLApp.Workbooks.Open(CurrentProject.Path & "\Invoice.xlsm")
    objXLApp.Application.Visible = True
End Sub
 

Users who are viewing this thread

Back
Top Bottom