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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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