Hello, I am kind of new to programming in VB (and programming in general). I am trying to program a (what I assume to be simple) action of having a form when clicked open up a Excel Document. I need the path of the file it reads from to be relative, since I will be distributing the excel and exe file on a CD and there is no way to predict what the drive letter will be. If you can offer any help, it would be much appreciated.

Dim xlTmp AS Excel.Application
Private Sub Form_Click()
Set xlTmp = New Excel.Application
    xlTmp.Workbooks.Open ("Excel_Start.xls")
    xlTmp.Visible = True
Unload Me
End Sub

If I leave the code like this, it doesn't see the Excel file, yet if I tell it the path for Excel_Start.xls (i.e. D:\Excel_Start.xls) then it works. Is there anyway to get around this, so it works on all CD drives and not only ones that are designated D: ?

9 Years
Discussion Span
Last Post by Witzbold

In vb6 the current path can be found using the App object as follows

xlTmp.Workbooks.Open (App.Path & "\Excel_Start.xls")

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.