View Single Post
  #18   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default How to get the current path

Compile a VB6 app that only contains one form and these lines:
Private Sub Form_Load()
MsgBox CurDir
End Sub

Create a shortcut to the app somewhere and set the StartIn to anything you
want. Click the short cut.
No need for the FileListBox.

AFAIK
The command line to the app is being told to set it's CurDir to the StartIn
value.
However, when you open an Excel file (which is not an executable), there is
no associtaed command line and hence no where for the StartIn parameter to
go.
Therefore Excel never knows about it.

NickHK

"Stefan Mueller" wrote in message
ups.com...
Hi NickHK

Thanks a lot for your replies and your time. I appreciate it very
much, but I think we are still not talking about the same.

In real Visual Basic (I'm using VB6) I add a FileListBox (e.g.
FileListBox1) to the Form I'd like to know the current path (directory
where the EXE file has been started or the path which is entered in
'Start in:' if a shortcut of the EXE file has been started).

Normally I hide the FileListBox with
FileListBox1.Visible = False
FileListBox1.ZOrder 1

In the Form_Load I read the current path:
Private Sub Form_Load()
...
CurrentPath = FileListBox1.Path
...
End Sub

Now CurrentPath represents either the directory where the EXE file has
been started or the path which is entered in 'Start in:' if a shortcut
of the EXE file has been started.
That's the way I do it in real VB and that works perfect.

Because VBA (e.g. Excel) doesn't now the FileListBox control I'm
trying to get the same information somehow else.

To get the directory where the XLS file has been started I can do in
VBA with
ActiveWorkbook.Path

But I don't know how to get in VBA the path which is entered in 'Start
in:' of the shortcut of the started shortcut of the XLS file.