File Path By Year and Month

L

Legacy 436357

Guest
Hi,

I have this code for file path for the Invoice PDF.

Code:
Private Sub CommandButton1_Click()
  Dim NxtRw As Long, CurrentPath As String, wFile As String
  On Error GoTo EnEvents
  If Range("J3").Value = "" Then
    NxtRw = 3
  Else
    NxtRw = Range("J2").End(xlDown).Offset(1).Row
  End If
  Application.EnableEvents = False
  
  Range("J" & NxtRw).Value = Range("H6").Value
  Range("K" & NxtRw).Value = Range("H3").Value
  Range("L" & NxtRw).Value = Format(Now(), "mm/dd/yyyy HH:MM:SS")
  
  MonthFolder = Format(Now, "MMM")
  CurrentPath = "C:\Users\BPeterson\Google Drive\Invoices\" & MonthFolder & "\"
  
 
  wFile = [H2] & " " & [H3] & " " & Format(Now(), "mm-dd-yyyy HH.MMam/pm") & ".pdf"   'must be hypen
  Range("B2:H53").ExportAsFixedFormat Type:=xlTypePDF, Filename:=CurrentPath & wFile, _
    Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=True


EnEvents:
  Application.EnableEvents = True
End Sub

Within the 'Invoices' folder I have years like 2019, 2020, 2021, etc. Then within those folders I have 12 folders Jan, Feb, Mar, etc.

Can the code be altered so the PDFs are saved to the proper sub folders by Month and Year?

Thank you
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Based on the code, it seems you also have month folders in the 'Invoices' folder. Is the code working fine to save the PDFs to those folders? If so, maybe change the line to:

Code:
[COLOR=#333333]CurrentPath = "C:\Users\BPeterson\Google Drive\Invoices\"[/COLOR][COLOR=#333333] & [/COLOR]Format(Now, "yyyy")[COLOR=#333333] & "\"[/COLOR][COLOR=#333333] & MonthFolder & "\"[/COLOR]
 
Upvote 0
Wow thank you so much I was trying to figure it out without success. I really appreciate everyone on here this forum is the best!!!

:):):)
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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