File name needs to include a date

cowells

New Member
Joined
Feb 21, 2016
Messages
21
Hi All

So I’m looking to open a macro enabled workbook “LoadFile” press a button (running a couple of macros).

1 button will create a new file, named “MasterFile_xx_xx_xxxx, where the x’s will be appended with the date supplied by the user in the loadfile workbook
2.button will copy worksheets from multiple folders and files to this new workbook
3.button will save the new book, make it active and close the “LoadFile” book

I have the code for 2/3 just struggling with 1
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi,​
for the first point you should use the Format VBA text function …​
 
Upvote 0
You can use it like
VBA Code:
Dim Fname As String
Fname = "MasterFile_" & Format(Range("A1").Value, "dd_mm_yyyy")
 
Upvote 0
You can use it like
VBA Code:
Dim Fname As String
Fname = "MasterFile_" & Format(Range("A1").Value, "dd_mm_yyyy")
Thanks, but the date is in the correct format already in cell k4 i.e xx_xx_xxxx, just need to save the file (to a web location..https://…etc) with the name, for example: Masterfile_29_06_2021 and then I can run (press) button tow & three to complete the details. I tried the above and got an error?
 
Upvote 0
Does the cell contain an actual date or text?
 
Upvote 0
Does the cell contain an actual date or text?
Hi text, i got the user to ‘select’ the three elements from a list, then joined those elements back together to produce the xx_xx_xxxx string. I just need to understand how I can save the file with the two strings 1.Name 2. Xx_xx_xxxx as one file name name in an agreed location. As the xx bit will change each week/month.
 
Upvote 0
In that case just use
VBA Code:
Dim Fname As String
Fname = "MasterFile_" & Range("A1").Value
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,833
Messages
6,127,157
Members
449,367
Latest member
w88mp

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