Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Browse to change current path

Is there something like GetOpenFileName that would open a dialog box
and allow me to browse to a folder and pick it as the new Current
Directory?

I can use GetOpenFileName and pick a file in the correct directory and
that seems to change the CurDir( ). However, it isn't as intuitive and
clicking on a folder then pressing OK.

Thanks.

- John

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Browse to change current path

After this post I discovered John Walkenbach's tip at
http://j-walk.com/ss/excel/tips/tip29.htm.

This seems to do the trick.

- John


John Michl wrote:
Is there something like GetOpenFileName that would open a dialog box
and allow me to browse to a folder and pick it as the new Current
Directory?

I can use GetOpenFileName and pick a file in the correct directory and
that seems to change the CurDir( ). However, it isn't as intuitive and
clicking on a folder then pressing OK.

Thanks.

- John


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Browse to change current path

Here is one way. IXL2002 has a browse dialog.

With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)

End With

Look up FileDialog in the VBA help

The pre XL2002 way is

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name As String = _
"Select a folder.") As String
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long

bInfo.pidlRoot = 0& 'Root folder = Desktop

bInfo.lpszTitle = Name

bInfo.ulFlags = &H1 'Type of directory to Return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog

'Parse the result
path = Space$(512)

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

End Function

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"John Michl" wrote in message
oups.com...
Is there something like GetOpenFileName that would open a dialog box
and allow me to browse to a folder and pick it as the new Current
Directory?

I can use GetOpenFileName and pick a file in the correct directory and
that seems to change the CurDir( ). However, it isn't as intuitive and
clicking on a folder then pressing OK.

Thanks.

- John



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Browse to change current path

Thanks Bob. I browsed through the help looking for things such as
GetFolderOpen but never ran across FileDialog. I'll need check it out.
It is much simpler than my other approaches. Thanks!

- John


Bob Phillips wrote:
Here is one way. IXL2002 has a browse dialog.

With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)

End With

Look up FileDialog in the VBA help

The pre XL2002 way is

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name As String = _
"Select a folder.") As String
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long

bInfo.pidlRoot = 0& 'Root folder = Desktop

bInfo.lpszTitle = Name

bInfo.ulFlags = &H1 'Type of directory to Return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog

'Parse the result
path = Space$(512)

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

End Function

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"John Michl" wrote in message
oups.com...
Is there something like GetOpenFileName that would open a dialog box
and allow me to browse to a folder and pick it as the new Current
Directory?

I can use GetOpenFileName and pick a file in the correct directory and
that seems to change the CurDir( ). However, it isn't as intuitive and
clicking on a folder then pressing OK.

Thanks.

- John


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
Browse For a File or Path and enter in a cell D. Jones Excel Discussion (Misc queries) 5 November 9th 07 04:07 PM
Browse button on form for folder path Greshter Excel Discussion (Misc queries) 2 January 12th 06 10:20 PM
how to change absolute path to relative path hwijgerse Excel Worksheet Functions 0 November 25th 05 07:18 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 01:00 PM.

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"