GetFolderName working only in one computer

backup69

Active Member
Joined
Jan 20, 2004
Messages
271
i use following code and have problem run this in other two test computers

Code:
Private Type BrowseInfo ' used by the function GetFolderName
    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

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

Function GetFolderName(Msg As String) As String
' returns the name of the folder selected by the user
Dim bInfo As BrowseInfo, path As String, r As Long
Dim x As Long, pos As Integer
    bInfo.pidlRoot = 0& ' Root folder = Desktop
    If IsMissing(Msg) Then
        bInfo.lpszTitle = "Select a folder."
        ' the dialog title
    Else
        bInfo.lpszTitle = Msg ' the dialog title
    End If
    bInfo.ulFlags = &H1 ' Type of directory to return
    x = SHBrowseForFolder(bInfo) ' display the dialog
    ' Parse the result
    path = Space$(512)
    r = SHGetPathFromIDList(ByVal x, ByVal path)
    If r Then
        pos = InStr(path, Chr$(0))
        GetFolderName = Left(path, pos - 1)
    Else
        GetFolderName = ""
    End If
End Function

and error (can't find object or library) on line:
path = Space$(512)

I not remember what special i installed to my computer.
 
There's various browse for folder routines easily found on the web. How about trying a different one (starting perhaps with the example Richard posted in this thread).
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try preceding the instance of Left with the library from which it comes:

VBA.Left$(strFileName, 1)

Incidentally, if this does work, it points to a problem with your library references. Have you had any other problems on these computers on which your routine fails?
 
Upvote 0
To:xenou
Yes i thank him and got his example to work. But her is a some global problem and because of that all other solutions not working, even simple commands.
I understand this problem is solved but not the right way. Avoiding some commands in the project will not bring me closer to truth.
 
Upvote 0
Try preceding the instance of Left with the library from which it comes:

VBA.Left$(strFileName, 1)

Incidentally, if this does work, it points to a problem with your library references. Have you had any other problems on these computers on which your routine fails?

Yes this is working solution even for the String$(MAX_PATH, vbNullChar).
Can you explain why other two computers need prefix VBA.?
 
Upvote 0
I think I've seen cases where an addin is interfering - perhaps some library that has defined its own functions such as Left/Right/Mid.
 
Upvote 0

Forum statistics

Threads
1,216,550
Messages
6,131,304
Members
449,642
Latest member
jobon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top