PDA

View Full Version : Solved: GetFolder with Pointer



gmaxey
08-25-2012, 07:56 AM
Can anyone explain why the second function won't point to the folder passed? Thanks.

Sub Test()
MsgBox GetFolder
MsgBox GetFolderWithPointer("C:\Program Files")
End Sub
Function GetFolder()
Dim oFolder As Object
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Demo", 0, "C:\Program Files")
GetFolder = oFolder.self.Path
End Function
Function GetFolderWithPointer(Optional Pointer As String = "")
Dim oFolder As Object
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Demo", 0, Pointer)
GetFolderWithPointer = oFolder.self.Path
End Function

Paul_Hossler
08-25-2012, 02:58 PM
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774065(v=vs.85).aspx




vRootFolder [in, optional]
Type: Variant


I just changed the call to Variant instead of String and it seems to work


Function GetFolderWithPointer(Optional Pointer As Variant = "")
Dim oFolder As Object
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Demo", 0, Pointer)
GetFolderWithPointer = oFolder.self.Path
End Function



Paul

gmaxey
08-25-2012, 03:18 PM
Paul,

Sure enough. Thanks.



http://msdn.microsoft.com/en-us/library/windows/desktop/bb774065(v=vs.85).aspx




I just changed the call to Variant instead of String and it seems to work


Function GetFolderWithPointer(Optional Pointer As Variant = "")
Dim oFolder As Object
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Demo", 0, Pointer)
GetFolderWithPointer = oFolder.self.Path
End Function



Paul

fumei
08-25-2012, 05:14 PM
Which means of course you can write it simply asFunction GetFolderWithPointer(Optional Pointer)