Open Folder - Cannot find folder

Frankietheflyer

New Member
Joined
Nov 17, 2017
Messages
30
Hi

My code checks to see if a folder exists and creates one if it doesn't before going on to produced a dynamic number of PDF documents and save them in the folder.

The Code works, but I decided to try and be clever and give the user the opportunity of opening the folder once all the PDFs had been produced by having a Yes / No message box.

All goes well until I click on "Yes" when the code fails and tells me the folder cannot be found. However, the folder IS there!

The created folder is called "FolderName" and hovering over that word in DeBug clearly shows the path and folder name in inverted comers ("C:\Users" & Environ("USERNAME") & ("\Documents\PDF Team Sheets for Meeting ").

Any ideas why the code can't find the folder please??

The relevant bit of code at the end of making the PDFs is as follows:

Code:
[FONT=Verdana][FONT=Verdana]OpenFolder = MsgBox("The PDF Team Sheets have been produced and are in the Documents folder" & Chr(13) & Chr(13) & "PDF Team Sheets for Meeting " & ThisWorkbook.Sheets("Race Meeting Information").Range("B3").Value & Chr(13) & Chr(13) & "Do you want to open the folder?", vbYesNo)[/FONT]

If OpenFolder = vbYes Then[/FONT]
[FONT=Verdana]
Call Shell("explorer.exe" & FolderName, vbNormalFocus)[/FONT]


[FONT=Verdana]Application.ScreenUpdating = True
Exit Sub[/FONT]
[FONT=Verdana]
Else[/FONT]
[FONT=Verdana]
Application.ScreenUpdating = True[/FONT]
[FONT=Verdana]End If[/FONT]
[FONT=Verdana]End Sub[/FONT]

Thanks

Frankie
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try adding a Space between explorer.exe and foldername in your call to shell
 
Upvote 0
That works! (although not sure why!)

Thanks jimrward. (Some great places in Fife including the 19th hole if I remember correctly)
 
Upvote 0
Explorer.exe is a program and foldername is a parameter you are passing to it so will require a space otherwise it will be presented as explorer.exefoldername which means nothing

Yes St. Andrews is where I went to high skool
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,150
Members
453,021
Latest member
Justyna P

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