Get path to current workbook

R

Robert Crandal

If I have a workbook that can be copied to and used in any
arbitrary folder, that means each workbook will have
a different path.

Is there a way to determine the path of a workbook??
(Or path of "ThisWorkbook")

Thank you!
 
K

Kerberos

If I have a workbook that can be copied to and used in any
arbitrary folder, that means each workbook will have
a different path.

Is there a way to determine the path of a workbook??
(Or path of "ThisWorkbook")

Thank you!

Hey Robert!
I use this function below. It presents a "click-and-choose" menu
where the user picks
the folder he wants. Then the code returns it as a string for you to
work. Quite simple, isn't?

First, declare this TYPE in your module:

Public Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

Then, use the code below:

Public Function folder_win() As String
Dim lpIDList As Long
Dim folder As String
Dim browse As BrowseInfo ' This TYPE was declared right above

lpIDList = SHBrowseForFolder(browse)
If (lpIDList) Then
folder = Space(260)
SHGetPathFromIDList lpIDList, folder
folder = Left(folder, InStr(folder, vbNullChar))
folder_win = folder
End If
End Function


Hope it helped you out!

Brazillian Hugs!

Ronaldo PARIS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top