Reputation: 45
I'm trying to use vba to save a file with name based on the content of a cell.
I have found the following resource which has been helpful.
https://www.excelhow.net/how-to-save-file-based-on-cell-value-in-excel.html
But the content of the cell that im trying to put in the file name is a date of format dd/mm/yyyy, is it possible to change the format in the file name to be yyyy-mm-dd, and how would i go about doing this
Any help would be appreciated :)
Upvotes: 0
Views: 112
Reputation: 2877
Say it's a defined range called myCell
; Just replace myCell.Value
in your code with Format(myCell.Value, "yyyy-mm-dd")
.
Upvotes: 1
Reputation: 8230
I my opinion what you need is to create a string in order to be used as a name by re structuring the date and not by changing the format of the date. You could use:
=YEAR(A1) & "-" &RIGHT("0" & MONTH(A1),2) & "-" & RIGHT("0" & DAY(A1),2)
Upvotes: 0
Reputation: 11
one simple solution would be to change the number formart of that cell before retrieving it to the name. For that you could use the code line below:
Selection.NumberFormat = "yyyy-mm-dd"
Upvotes: 1