Opening folder with VBA. One Sub works, one Sub doesn't...

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
Good morning.

I have a variation of this code I use under command buttons on two userforms. It opens a folder based on a path specified in a text box on the userforms.

This works correctly opening the desired folder:

VBA Code:
Private Sub Reactivate_OPEN_Click()
Dim FolderPath As String
FolderPath = Me.Reactivate_Sub_Full_Name.Value
Call Shell("explorer.exe " & FolderPath, vbMaximizedFocus)
End Sub

Using almost the same code on another userform opens an Explorer window to my Documents folder instead of the desired folder:

VBA Code:
Private Sub cmdOpenFolder_Click()
Dim FolderPath As String
FolderPath = Me.SE_SubLotFolderPath.Value
Call Shell("explorer.exe " & FolderPath, vbMaximizedFocus)
End Sub

Not sure what I'm doing wrong here.
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Stab in the dark...it looks like SE_SubLotFolderPath may not have a valid path.
before your 'call' command try add
VBA Code:
msgbox folderpath
to see 1. if the value exists and 2. to confirm if the value is valid, ie not missing any '\' at the end, etc.
 
Upvote 0
Stab in the dark...it looks like SE_SubLotFolderPath may not have a valid path.
before your 'call' command try add
VBA Code:
msgbox folderpath
to see 1. if the value exists and 2. to confirm if the value is valid, ie not missing any '\' at the end, etc.

You stirred my brain! I had / instead of \. Once I fixed that it opened fine. Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,680
Members
449,091
Latest member
peppernaut

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