Make directory

rakupareek

New Member
Joined
Dec 29, 2023
Messages
38
Office Version
  1. 2016
Platform
  1. 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
Hi Every one,
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.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
If there are date in J6 is 16-10-2023 then directory make D\Estimate\2023\Oct
 
Upvote 0
I think this should do what you want:
VBA Code:
filepath = "D:\Estimate\" & Format(Range("J6"), "yyyy") & "\" & Format(Range("J6"), "mmm") & "\"
 
Upvote 0
Sorry, you need to make the directory first. Similar methodology to what I gave you.

I think you may need to first create the year directory, and then the month directory, i.e.
Excel Formula:
MkDir "D:\Estimate\" & Format(Range("J6"), "yyyy") & "\" 
MkDir "D:\Estimate\" & Format(Range("J6"), "yyyy") & "\" & Format(Range("J6"), "mmm") & "\"
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,223,869
Messages
6,175,087
Members
452,611
Latest member
bls2024

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