954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Open Excel in VB6

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

Witzbold
Newbie Poster
6 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

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

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

davidcairns
Junior Poster
114 posts since Feb 2007
Reputation Points: 12
Solved Threads: 8
 

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

Witzbold
Newbie Poster
6 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You