Forum

Convert Macro from ...
 
Notifications
Clear all

Convert Macro from DATE to Version

4 Posts
3 Users
0 Reactions
67 Views
(@webbers)
Posts: 148
Reputable Member
Topic starter
 

I thought converting an existing macro from Date to version (with leading zeros) would be somewhat easy.  I was very wrong!  Below is my macro which works great.  It does a save as to today's date based on the cell reference that indicates the file name.  Now I have added in the 2nd variable which is the version (cell H4).  I need this to be display in the format of "000". So the File name would change like this shown below.  I DID leave in the date portion of the previous macro, as I didn't want to mess everything up.

Sherry's Development File - 007.xlsb

Sherry's Development File - 008.xlsb

Option Explicit

Sub File_Name_As_Cell_Date()

Dim File_Name As String
Dim Destination As String

Application.DisplayAlerts = False

Destination = ThisWorkbook.Path & "" & File_Name

' 2nd variable uses custom number format for versioning development files
File_Name = Range("E4").Value & Range("H4").NumberFormat = "mm-dd-yyyy" & ".xlsb"

' xlExcel12 is for xlsb
ActiveWorkbook.SaveAs Destination & File_Name, xlExcel12

Application.DisplayAlerts = True

''ActiveWorkbook.Close
End Sub

 
Posted : 11/03/2023 2:51 pm
(@keebellah)
Posts: 373
Reputable Member
 

What's the 007 or the 008? Is that a counter? What does that have to do with the date?

 
Posted : 12/03/2023 3:19 am
(@debaser)
Posts: 837
Member Moderator
 

You can use something like this:

 

File_Name = Range("E4").Value & Format$(Range("H4").Value, "000") & ".xlsb"

 
Posted : 14/03/2023 4:55 am
(@webbers)
Posts: 148
Reputable Member
Topic starter
 

@Velouria

Perfect!!!!  Thanks so much!  I kept getting "FALSE" for my filename with all my attempts!  Thanks so much!

 
Posted : 17/03/2023 5:35 pm
Share: