rakupareek
New Member
- Joined
- Dec 29, 2023
- Messages
- 38
- Office Version
- 2016
- Platform
- Windows
VBA Code:
Sub pdf()
Application.ScreenUpdating = False
Dim pdf_range As Range
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Estimate")
Set pdf_range = ws.Range("B5:J34")
Dim fileName As String
fileName = Left(Range("B7").Value, 50) & " - " & Left(Range("J6").Value, 10)
Dim filePath As String
filePath = "D:\Estimate\" & fileName & ".pdf"
On Error Resume Next
MkDir "D:\Estimate\"
On Error GoTo 0
On Error Resume Next
pdf_range.ExportAsFixedFormat Type:=xlTypePDF, fileName:=filePath, OpenAfterPublish:=False
If Err.Number <> 0 Then
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Error Exporting PDF"
Else
MsgBox "PDF File Generated Successfully!", , "Jagdamba Jewellers"
End If
Application.ScreenUpdating = True
End Sub
I have this code in which directory make in D drive named Estimate in which directly file downloaded.
I let u know that cell J6 contain date
Now I want to make directory in D drive Estimate\Year\month and after that file downloaded in month folder.
Please help me to amend this code.