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: ?

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

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

Thank You very much, that is what I was missing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.