Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to get the current path

I've created a shortcut of an Excel sheet (e.g. Example.xls). On the
shortcut I do a right mouse click and then click properties. In 'Start
in:' I type 'C:\Temp'. Now I double click the shortcut 'Example.xls'
and like to get the current path (in this example 'C:\Temp').

In real VB I do it with a FileListBox:
MsgBox (FileListBox1.Path)

But how can I do it in VBA (e.g. Excel)?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default How to get the current path

Stefan,

You can use the CurDir function to get the current directory..


--
Hope that helps.

Vergel Adriano


"Stefan Mueller" wrote:

I've created a shortcut of an Excel sheet (e.g. Example.xls). On the
shortcut I do a right mouse click and then click properties. In 'Start
in:' I type 'C:\Temp'. Now I double click the shortcut 'Example.xls'
and like to get the current path (in this example 'C:\Temp').

In real VB I do it with a FileListBox:
MsgBox (FileListBox1.Path)

But how can I do it in VBA (e.g. Excel)?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default How to get the current path

activeworkbook.Path


--


Gary


"Stefan Mueller" wrote in message
oups.com...
I've created a shortcut of an Excel sheet (e.g. Example.xls). On the
shortcut I do a right mouse click and then click properties. In 'Start
in:' I type 'C:\Temp'. Now I double click the shortcut 'Example.xls'
and like to get the current path (in this example 'C:\Temp').

In real VB I do it with a FileListBox:
MsgBox (FileListBox1.Path)

But how can I do it in VBA (e.g. Excel)?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to get the current path

Thanks for your reply.

CurDir is not bad but it doesn't really care what is written in 'Start
in:' resp. from which path I've startet the Excel workbook.

If I start the Excel workbook e.g. from the Desktop it should show 'C:
\Documents and Settings\Administrator\Desktop'.
If in 'Start in:' of the shortcut of the Excel workbook is written 'C:
\Temp' it should show 'C:\Temp'.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to get the current path

ActiveWorkbook.Path is closer to my wanted function than CurDir
because it shows e.g. 'C:\Documents and Settings\Administrator
\Desktop' if I start the Excel workbook from the Desktop.
However, it doesn't show 'C:\Temp' if in 'Start in:' of the shortcut
of the Excel workbook is written 'C:\Temp'.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default How to get the current path

if i open a workbook from c:\temp it returns c:\temp

from the immediate window

?activeworkbook.Path
C:\Temp

--


Gary


"Stefan Mueller" wrote in message
ups.com...
ActiveWorkbook.Path is closer to my wanted function than CurDir
because it shows e.g. 'C:\Documents and Settings\Administrator
\Desktop' if I start the Excel workbook from the Desktop.
However, it doesn't show 'C:\Temp' if in 'Start in:' of the shortcut
of the Excel workbook is written 'C:\Temp'.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to get the current path

I don't think that the workbook file itself is in C:\temp. The workbook could
be anywhere. But there's a shortcut on the desktop that points to the correct
location.

But inside that shortcut (rightclick on it and choose properties, then Shortcut
tab) you'll see another spot to specify a "start in" folder.

I have no idea how to get that information based on the opened workbook.

Gary Keramidas wrote:

if i open a workbook from c:\temp it returns c:\temp

from the immediate window

?activeworkbook.Path
C:\Temp

--

Gary

"Stefan Mueller" wrote in message
ups.com...
ActiveWorkbook.Path is closer to my wanted function than CurDir
because it shows e.g. 'C:\Documents and Settings\Administrator
\Desktop' if I start the Excel workbook from the Desktop.
However, it doesn't show 'C:\Temp' if in 'Start in:' of the shortcut
of the Excel workbook is written 'C:\Temp'.


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to get the current path

Like already mentioned, in real VB the FileListBox (FileListBox1.Path)
shows this information.
Unfortunately there's no FileListBox in VBA. Therefore I'm looking for
another way to get this information.

ActiveWorkbook.Path is fine if you start the real Excel sheet. But it
does not work if you start the Excel sheet via a shotcut. In that case
ActiveWorkbook.Path still shows the path where the real Excel sheet is
located and not where the shortcut is located resp. what is defined in
'Start in:'.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How to get the current path

"Start In" in a short cut can point to any valid location, but it seems to
be ignored by Excel, if indeed Excel is even told about that setting,
possibly via DDE if anything.
Excel would seems to read from .DefaultFilePath instead upon start up.

Also I don't see how VB5/6's FileListBox exposes the StartIn parameter of a
short cut.

If you make a simple VB5/6 app with only a command button:

Private Sub Command1_Click()
MsgBox CurDir
End Sub

and start the app with various shortcut pointing to different StartIn
folders, you can see the changes.

Excel does not seem to work like this though.
Out of curiousity, why does it matter ?

NickHK

"Stefan Mueller" wrote in message
ps.com...
Like already mentioned, in real VB the FileListBox (FileListBox1.Path)
shows this information.
Unfortunately there's no FileListBox in VBA. Therefore I'm looking for
another way to get this information.

ActiveWorkbook.Path is fine if you start the real Excel sheet. But it
does not work if you start the Excel sheet via a shotcut. In that case
ActiveWorkbook.Path still shows the path where the real Excel sheet is
located and not where the shortcut is located resp. what is defined in
'Start in:'.



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to get the current path

I still don't know how to get that path.

But if you know the shortcut name (including location), you could read the
shortcut and find out.

Stefan Mueller wrote:

Like already mentioned, in real VB the FileListBox (FileListBox1.Path)
shows this information.
Unfortunately there's no FileListBox in VBA. Therefore I'm looking for
another way to get this information.

ActiveWorkbook.Path is fine if you start the real Excel sheet. But it
does not work if you start the Excel sheet via a shotcut. In that case
ActiveWorkbook.Path still shows the path where the real Excel sheet is
located and not where the shortcut is located resp. what is defined in
'Start in:'.


--

Dave Peterson


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to get the current path

Hello Dave

Thanks for your hint but I'm still hoping that someone knows a way to
get the path entered in 'Start in:'.

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How to get the current path

I don't think Excel ever knows it, so consequently cannot tell you.
From an Excel point of view, why does it matter as it does seem to affect
Excel.

NickHK

"Stefan Mueller" wrote in message
ps.com...
Hello Dave

Thanks for your hint but I'm still hoping that someone knows a way to
get the path entered in 'Start in:'.



  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to get the current path

Hmm, but how can the VB's FileListBox do it?
I'm trying to find a way to get this information because I'd like to
open another file from the same directory I've started the Excel file
resp. Excel shortcut.

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How to get the current path

I don't see how a VB FileListbox helps. How can that control tell you the
location of the short cut that open a file ?
Show your VB code that does that.

NickHK

"Stefan Mueller" wrote in message
oups.com...
Hmm, but how can the VB's FileListBox do it?
I'm trying to find a way to get this information because I'd like to
open another file from the same directory I've started the Excel file
resp. Excel shortcut.



  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to get the current path

You understood me wrong.
I just want to mention that in real VB I can get the information
entered in 'Start in:' of a shortcut with a FileListBox:
MsgBox (FileListBox.Path)

Unfortunately VBA doesn't have a FileListBox and therefore I'm looking
for another way to get this information.



  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How to get the current path

Stefan,
I still don't see how "MsgBox (FileListBox.Path)" tells you anything about
the StartIn setting of a short cut, but this may help:
http://www.vbaccelerator.com/home/Vb...ts/article.asp

NickHK

"Stefan Mueller" wrote in message
ups.com...
You understood me wrong.
I just want to mention that in real VB I can get the information
entered in 'Start in:' of a shortcut with a FileListBox:
MsgBox (FileListBox.Path)

Unfortunately VBA doesn't have a FileListBox and therefore I'm looking
for another way to get this information.



  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to get the current path

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.

  #18   Report Post  
Posted to microsoft.public.excel.programming
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.



  #19   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to get the current path

Hi NickHK

You are absolutely right!
In VB6 the function CurDir does exactly what I tried to do with a
hidden FileListBox.
Many thanks for that hint and sorry for my confusion. I'm still a
beginner ;-)

I don't exactly know which path the function CurDir in VBA (e.g.
Excel) shows. I just now it's not the path entered in 'Start In:'.
If I understand you right: there is no possibility to read the path
entered in 'Start In:' within VBA because Excel doesn't know how it
(the worksheet) has been started (direct or via shortcut) because it's
not an executable.
Is this correct?

Many thanks
Stefan

  #20   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How to get the current path

Stefan,
Yes, that's what I understand.

You could put some code in the Workbook_Open event of the workbook in
question to set CurDir, but this obviously will not be linked to the StartIn
parameter of the short cut.

NickHK

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

You are absolutely right!
In VB6 the function CurDir does exactly what I tried to do with a
hidden FileListBox.
Many thanks for that hint and sorry for my confusion. I'm still a
beginner ;-)

I don't exactly know which path the function CurDir in VBA (e.g.
Excel) shows. I just now it's not the path entered in 'Start In:'.
If I understand you right: there is no possibility to read the path
entered in 'Start In:' within VBA because Excel doesn't know how it
(the worksheet) has been started (direct or via shortcut) because it's
not an executable.
Is this correct?

Many thanks
Stefan



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding Current Path Mike C Excel Programming 1 April 7th 05 09:14 PM
Current Workbook Path MarkTheNuke Excel Programming 0 February 21st 05 04:33 AM
Current Workbook Path windsurferLA Excel Programming 1 February 19th 05 04:19 PM
Current Workbook Path MarkTheNuke Excel Programming 0 February 19th 05 06:31 AM
Current path to Qualified Path Mary Excel Programming 1 October 14th 04 02:42 PM


All times are GMT +1. The time now is 07:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"