A family of Microsoft word processing software products for creating web, email, and print documents.
I have this macro but get compile error below. why - how to solve?
You forgot to declare the external function SHBrowseForFolder, but that would not solve your problem when you have a 64-bit office.
You can call the same dialog in a more elegant way:
Sub Example_ShellGetFolder()
Debug.Print ShellGetFolder(CSIDL_PERSONAL, "Select a folder", BIF_BrowseFolder)
End Sub
Function ShellGetFolder( _
Optional RootPath As Variant = CSIDL_PERSONAL, _
Optional Caption As String = "", _
Optional Options As vbShellGetFolderFlags = BIF_DefaultOptions) As String
'http://msdn.microsoft.com/en-us/library/windows/desktop/bb774065(v=vs.85).aspx
'RootPath kann ein String oder CSIDL-Konstante sein
Dim objShell As Object, objBrowse As Object
On Error Resume Next
Set objShell = CreateObject("Shell.Application")
'Dialog starten und RootPath zurückgeben
If IsNumeric(RootPath) Then
'Anfangspfad als Konstante
Set objBrowse = objShell.BrowseForFolder(&H0, Caption, Options, CLng(RootPath))
Else
'Anfangspfad als String
Set objBrowse = objShell.BrowseForFolder(&H0, Caption, Options, RootPath & Chr(0))
End If
ShellGetFolder = objBrowse.Self.Path
End Function
But I recommend not to use it, the best way is to use Application.FileDialog, have a look into the help, there is an example.
Andreas.