Folder selection under VBA?

Hello

When I ask to select a folder in VBA, I find the path not intuitive at all. Anyone know of a command to open a Windows Explorer type window that would allow a double-click expansion of folders?

I use the following command:

'Choice of file
 FlagChoix = &H1
    Msg = "Select Folder:"
    Set objShell = CreateObject("Shell.Application")
     On Error Resume Next
        Set objFolder = objShell.BrowseForFolder(&H0&, Msg, FlagChoix)
         If NbPoint = 0 Then
         Path = objFolder.ParentFolder.ParseName(objFolder.Title). Path & ""
         Else
         Exit Sub
         End If

 

Thanks in advance,

1 Like

Hello

I created a small tutorial to open Windows Explorer to choose a folder, it's quite practical:

http://www.lynkoa.com/tutos/3d/selectionner-un-repertoire-en-vba

If the tutorial doesn't work I can put the file in PC here, just ask.

2 Likes

Hello

I want the file in PJ, tutorials don't work for me a priori...

Thank you!

1 Like

Maybe a bug, because I don't have access to your tutorial either@PL

1 Like

Yes the tutorials don't work, it's a bug reported to the staff, and unfortunately it hasn't been solved with the update of October 1st...

http://www.lynkoa.com/tutos/3d/selectionner-un-repertoire-en-vba

 

The code to include in a macro is here:

http://we.tl/C85tB1qRGr

3 Likes

So, I'm getting it back too, it can always be useful to me one day. Haha

1 Like

.PL, would it be possible to send the tutorial as well? The code doesn't work for me, it might help me understand...

"FileDialog" is not recognized. If you have a lead I'm interested, if not I'll dig in a while.

A +

 

Hello

With a little research:

GirlDialog: https://msdn.microsoft.com/fr-fr/library/office/ff836226.aspx

There are dozens of examples on the web

1 Like

Sorry my previous code works for Excel, and I assumed it would also work for SolidWorks without testing but it doesn't!

Here's the right file:

http://we.tl/CgWO3GxU8T

And the right tutorial:

http://www.lynkoa.com/tutos/solidworks/api-solidworks-explorateur-windows-pour-selection-de-fichier-vba-0

 

 

2 Likes

@remrem: it's precisely the FileDialog that is not compatible with SolidWorks, but only Excel!

1 Like

I put myself -1!

;-)

1 Like