VBA to open filepath where year and month change

tonyjyoo

Board Regular
Joined
Aug 5, 2016
Messages
167
Hello,

I need some assistance with VBA to open a file where the year, month, and days change on a daily basis.

The filepath will be as such:
Code:
S:\NPH Accounting\NPH Accounting Department\Treasury\2016\5 NPH FundServ\01 Daily\DTCC Settlement Reports Daily\05 Current Day DTCC Settlement\05 NPH\12 DTCC Current Day\NPH DTCC 12.19 CD MF.xlsx"

- So the "2016" after Treasury will change on a yearly basis
- The month (in "12 DTCC Current Day" segment) will change on a monthly basis
- and the file name "NPH DTCC 12.19.CD MF.xlsx" will change on a daily basis.

Can someone help me construct this into VBA? I will be using this to run a macro every day, so it would be convenient.

Thanks in advance!!!!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
This would give you that filepath based on the current date:

Code:
Sub test()
Dim dt As Date
dt = Date
filepath = "S:\NPH Accounting\NPH Accounting Department\Treasury\" & Format(dt, "yyyy") & "\5 NPH FundServ\01 Daily\DTCC Settlement Reports Daily\05 Current Day DTCC Settlement\05 NPH\" & Format(dt, "mm") & " DTCC Current Day\NPH DTCC " & Format(dt, "mm.dd") & " CD MF.xlsx"
MsgBox filepath
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,731
Members
449,093
Latest member
Mnur

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