View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Knowing what Folder I'm in when I open from a shortcut

I lost my last reply part way through so not sure if it posted but here it is
again because it was not all there.

I am still not sure exactly what it is you want but the following code out
of help (modified with the filespec) will give you the path of the workbook.

Sub ShowFileAccessInfo()
Dim filespec
Dim fs, d, f, s

filespec = ThisWorkbook.Name

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filespec)
s = UCase(f.Path) & vbCrLf
s = s & "Created: " & f.DateCreated & vbCrLf
s = s & "Last Accessed: " & f.DateLastAccessed & vbCrLf
s = s & "Last Modified: " & f.DateLastModified
MsgBox s, 0, "File Access Info"
End Sub

--
Regards,

OssieMac


"Héctor Miguel" wrote:

hi, !

I start from a folder.
I open an excel file from a shorcut (to another folder)
but I am still in the original folder I started in.


at that moment, you know exactly which folder you are and/or
where is located the short-cut link-file to open your document/excel

My question is how the in Excel VBA programming environment can I know
what folder I started the Excel program from (not the folder the excel program is in).


suppose excel is closed, and suddenly it opens by means of... whatever, so...
how would excel be sure and tell you where you were while excel opens ?
- an hyperlink from another application (word, ppt, ...) ???
- a shorcut from your desktop ???
- a shortcut from windows-explorer or MyPC, or... ???

AFAIK, when excel opens from a shortcut, it's current directory is still the Application.DefaultFilePath

hth,
hector.