Cannot create a directory

colinharwood

Active Member
Joined
Jul 27, 2002
Messages
440
Office Version
  1. 365
Platform
  1. Windows
Hi
When using the following code, I get a runtime error 76, path not found, when the mkdir line is reached can anyone please explain what is wrong.
Thanks

Sub PrintPDFCard()

Dim ThisFile As String
Dim FileDrive As String
Dim strFolderName As String
Dim strFolderExists As String

'Check if folder exists
strFolderName = "C:\users\adria\tonbridge mes folders\TMES email renewals"
strFolderExists = Dir(strFolderName, vbDirectory)

If strFolderExists = "" Then
'If folder doesn't exist"
MkDir "C:\users\adria\tonbridge mes folders\TMES email renewals\"
Else
'If folder does exist
GoTo CreatePDF
End If

CreatePDF:

CreateObject("WScript.Network").SetDefaultPrinter "Microsoft Print to PDF"

Range("$A$1:$H$42").Select
ThisFile = Range("N3").Value & " " & Range("O3").Value
FileDrive = "C:\TMES email renewals\"
Selection.PrintOut Copies:=1, ActivePrinter:= _
"Microsoft print to pdf", Collate:=True, _
printtofile:=True, prtofilename:=FileDrive & ThisFile & ".pdf"
Sheets("PDF Membership Card").Range("S1").Select

CreateEmail:

' Create Email to someone
sCmd = "C:\Program Files\Mozilla Thunderbird\thunderbird.exe"
Email = Range("N4").Value 'email address
Subject = "PDF Membership Card"
Content = "Hi%20%0A%0APlease find attached a PDF Membership Card%20%0A%0ARegards%0A%0AAdrian Banks%0A%0ATreasurer"
Attch = "C:\TMES email renewals\" & ThisFile & ".pdf" ' file name and path
sCmd = sCmd & " -compose " & "to=" & Email
sCmd = sCmd & ",subject=" & Subject
sCmd = sCmd & ",attachment=" & Attch
sCmd = sCmd & ",body=" & Content
Call Shell(sCmd, vbNormalFocus)

End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
VBA Code:
strFolderName = "C:\users\adria\tonbridge mes folders\TMES email renewals"

Does tonbridge mes folders already exist ? If not ... you'll need to create that folder first ... then you can use the above line to create the last folder TMES email renewals
 
Upvote 0
You can create a Folder and Subfolder at the same time, but the coding needs to be different.

Here is one example that might assist in understanding : Macro to Create Folders and Subfolders

You can always GOOGLE : vba create folder and subfolder
 
Upvote 0
so you can only create one sub folder at a time.
Hi, as you are under Windows it can be achieved at once just using MakeSureDirectoryPathExists like in this thread :​
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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