Open Folder - Cannot find folder

Frankietheflyer

New Member
Joined
Nov 17, 2017
Messages
26
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:

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,702
Try adding a Space between explorer.exe and foldername in your call to shell
 

Frankietheflyer

New Member
Joined
Nov 17, 2017
Messages
26
That works! (although not sure why!)

Thanks jimrward. (Some great places in Fife including the 19th hole if I remember correctly)
 

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,702
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
 

Forum statistics

Threads
1,077,784
Messages
5,336,328
Members
399,076
Latest member
vullistax

Some videos you may like

This Week's Hot Topics

Top