Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Folder picker default - second attempt...
Hello, I hope someone can help me please.
I am using the built-in folder picker: Application.FileDialog(msoFileDialogFolderPicker) And I would like to have it initially display all of our network shares along with the local drives. On our network, this is equivalent to clicking "Computer" which I think is equivalent to "My Computer". I know you can name an initial path using: ...InitialFileName = "{my path}" But I can't seem to get it to default to "computer" or at least to a listing of the network shares. Does anyone know how to do this? Your example code is mostly what I need. Thanks in advance for your assistance... .. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Folder picker default - second attempt...
I didn't have any luck either trying to get the dialog to open at My
Computer. If no one comes up with an answer you might want to consider a different approach. The following uses a built-in Windows function to create an interface for picking a folder. The Windows' SHBrowseForFolder function actually provides many more options than this example shows, but it may be all you need. For a more complete example look at the BrowseForFolder demo I uploaded to Stephen Bullen's site (http://www.bmsltd.co.uk/MVP/Default.htm). -- Jim Rech Excel MVP Public 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 'Main Browse for directory function Declare Function SHBrowseForFolder Lib "shell32.dll" _ Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long 'Gets path from pidl Declare Function SHGetPathFromIDList Lib "shell32.dll" _ Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Sub Demo() Dim RetStr As String RetStr = GetDirectory("Choose path") If RetStr < "" Then MsgBox RetStr End Sub Function GetDirectory(Optional Msg) As String Dim bInfo As BROWSEINFO Dim Path As String Dim ItemIdentifierListAddress As Long Dim Success As Boolean bInfo.pidlRoot = 0 'Root folder = Desktop If Not IsMissing(Msg) Then bInfo.lpszTitle = Msg 'Display the dialog ItemIdentifierListAddress = SHBrowseForFolder(bInfo) 'Get path string from ID GetDirectory = GetPathFromID(ItemIdentifierListAddress) End Function 'Converts a PIDL to a string Function GetPathFromID(ID As Long) As String Dim Result As Boolean, Path As String * 255 Result = SHGetPathFromIDList(ID, Path) If Result Then GetPathFromID = Left(Path, InStr(Path, Chr$(0)) - 1) Else GetPathFromID = "" End If End Function |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Folder picker default - second attempt...
Jim, your work around does the trick, thanks! I'll also
have a look at the site you mentioned. Cheers. -----Original Message----- I didn't have any luck either trying to get the dialog to open at My Computer. If no one comes up with an answer you might want to consider a different approach. The following uses a built-in Windows function to create an interface for picking a folder. The Windows' SHBrowseForFolder function actually provides many more options than this example shows, but it may be all you need. For a more complete example look at the BrowseForFolder demo I uploaded to Stephen Bullen's site (http://www.bmsltd.co.uk/MVP/Default.htm). -- Jim Rech Excel MVP Public 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 'Main Browse for directory function Declare Function SHBrowseForFolder Lib "shell32.dll" _ Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long 'Gets path from pidl Declare Function SHGetPathFromIDList Lib "shell32.dll" _ Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Sub Demo() Dim RetStr As String RetStr = GetDirectory("Choose path") If RetStr < "" Then MsgBox RetStr End Sub Function GetDirectory(Optional Msg) As String Dim bInfo As BROWSEINFO Dim Path As String Dim ItemIdentifierListAddress As Long Dim Success As Boolean bInfo.pidlRoot = 0 'Root folder = Desktop If Not IsMissing(Msg) Then bInfo.lpszTitle = Msg 'Display the dialog ItemIdentifierListAddress = SHBrowseForFolder(bInfo) 'Get path string from ID GetDirectory = GetPathFromID (ItemIdentifierListAddress) End Function 'Converts a PIDL to a string Function GetPathFromID(ID As Long) As String Dim Result As Boolean, Path As String * 255 Result = SHGetPathFromIDList(ID, Path) If Result Then GetPathFromID = Left(Path, InStr(Path, Chr$(0)) - 1) Else GetPathFromID = "" End If End Function . |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Folder picker default - second attempt...
pk,
As an easier alternative to Jim's API approach: Set a reference to Microsoft Scripting Runtime then have a look at (Scripting) .FileSystemObject plenty to find with google! keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "pk" wrote: Jim, your work around does the trick, thanks! I'll also have a look at the site you mentioned. Cheers. -----Original Message----- I didn't have any luck either trying to get the dialog to open at My Computer. If no one comes up with an answer you might want to consider a different approach. The following uses a built-in Windows function to create an interface for picking a folder. The Windows' SHBrowseForFolder function actually provides many more options than this example shows, but it may be all you need. For a more complete example look at the BrowseForFolder demo I uploaded to Stephen Bullen's site (http://www.bmsltd.co.uk/MVP/Default.htm). -- Jim Rech Excel MVP Public 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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Folder picker default - second attempt...
Jim,
A bit of serendipity! I was required to write exactly the same procedure, and failing dismally. Logged onto the group and hey presto, there is the answer. Many many thanks. John Redmayne -----Original Message----- I didn't have any luck either trying to get the dialog to open at My Computer. If no one comes up with an answer you might want to consider a different approach. The following uses a built-in Windows function to create an interface for picking a folder. The Windows' SHBrowseForFolder function actually provides many more options than this example shows, but it may be all you need. For a more complete example look at the BrowseForFolder demo I uploaded to Stephen Bullen's site (http://www.bmsltd.co.uk/MVP/Default.htm). -- Jim Rech Excel MVP Public 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 'Main Browse for directory function Declare Function SHBrowseForFolder Lib "shell32.dll" _ Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long 'Gets path from pidl Declare Function SHGetPathFromIDList Lib "shell32.dll" _ Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Sub Demo() Dim RetStr As String RetStr = GetDirectory("Choose path") If RetStr < "" Then MsgBox RetStr End Sub Function GetDirectory(Optional Msg) As String Dim bInfo As BROWSEINFO Dim Path As String Dim ItemIdentifierListAddress As Long Dim Success As Boolean bInfo.pidlRoot = 0 'Root folder = Desktop If Not IsMissing(Msg) Then bInfo.lpszTitle = Msg 'Display the dialog ItemIdentifierListAddress = SHBrowseForFolder(bInfo) 'Get path string from ID GetDirectory = GetPathFromID (ItemIdentifierListAddress) End Function 'Converts a PIDL to a string Function GetPathFromID(ID As Long) As String Dim Result As Boolean, Path As String * 255 Result = SHGetPathFromIDList(ID, Path) If Result Then GetPathFromID = Left(Path, InStr(Path, Chr$(0)) - 1) Else GetPathFromID = "" End If End Function . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how can i change my default working folder to a networked folder? | Excel Discussion (Misc queries) | |||
"Save As" folder -- can I default this to the same folder as origi | Excel Discussion (Misc queries) | |||
Save as Default folder | Excel Discussion (Misc queries) | |||
Folder picker: default to network share? | Excel Programming | |||
GetOpenFilename - Default Folder | Excel Programming |