Hello,
I'm having trouble getting a macro i found here on this site to work, i have tried to do some modifications, but VB is certainly not my strong side...
This is the macro:
I found it here: https://www.mrexcel.com/forum/excel...df-macro-using-custom-file-folder-name-2.html
The thing is that i need the macro to save the file in a subfolder (SubFolderName = C2")
Foldername is C1
Filename is C3 in the excel file.
When the directory does not exist i get an error saying the "Runtime Error 76, the path is not found" and this part is marked Yellow in the VB editor:
Anyone got any tips for me here?
I'm having trouble getting a macro i found here on this site to work, i have tried to do some modifications, but VB is certainly not my strong side...
This is the macro:
Code:
Sub Make_PDF()' Create and save .pdf
Dim pdfName As String, FolderName As String, SubFolderName As String, FullName As String
pdfName = Range("C3").Text
FolderName = Range("C1").Text
SubFolderName = Range("C2").Text
If Not DirExists("C:\Invoices\" & FolderName & "\" & SubFolderName & "\") Then MkDir "C:\Invoices\" & FolderName & "\" & SubFolderName & "\"
FullName = "C:\Invoices\" & FolderName & "\" & SubFolderName & "\" & pdfName & ".pdf"
If MsgBox("Please confirm that name and location is correct: " & FullName & ". - " & " Is it correct?", vbYesNo + vbQuestion, "Confirm File Name and Location") = vbNo Then Exit Sub
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FullName _
, Quality:=xlQualityMedium, IncludeDocProperties:=False, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
YesNo = MsgBox("Would you like to open the folder where the invoice was saved?" _
, vbYesNo + vbQuestion, "Open Folder?")
Select Case YesNo
Case vbYes
myval = Shell("explorer C:\Invoices\" & FolderName & "\" & SubFolderName & "\", 1)
Case vbNo
End Select
End Sub
Function DirExists(sSDirectory As String) As Boolean
If Dir(sSDirectory, vbDirectory) <> "" Then DirExists = True
End Function
I found it here: https://www.mrexcel.com/forum/excel...df-macro-using-custom-file-folder-name-2.html
The thing is that i need the macro to save the file in a subfolder (SubFolderName = C2")
Foldername is C1
Filename is C3 in the excel file.
When the directory does not exist i get an error saying the "Runtime Error 76, the path is not found" and this part is marked Yellow in the VB editor:
Code:
MkDir "C:\Invoices\" & FolderName & "\" & SubFolderName & "\"
Anyone got any tips for me here?