Automatic File Naming (Date, Version)
Hi all,
I want to code a makro for automatic naming and versioning. The format for a file is YYYY-MM-DD_file_V1.pptx
My code works for presentations which are named without any date, e.g. mypresentation.pptx -> This will be named into 2018-01-02_mypresentation_V01.pptx. (Actually the V1 part is currently NOT working, the V1 suffix is added after the .pptx)
If you save the file (2018-01-02_mypresentation_V1.pptx) again, the file will be saved as 2018-01-02_ion.pptxV1_ due to the wrong usage of "Mid..."
I think of repairing my code by the use of variables and if Loops.Or I might use sth like
strDotPosition = InStrRev(ActivePresentation.Name, ., [-1], [vbTextCompare]) to find the dot from .pptx.
Maybe somebody can give me a good hint/workaround, how to fix my code in a nice, smart way.
My code so far:
Code:
Sub SaveAsButton()
Dim saveAs As FileDialog
Dim strFileName As String
' Dim strVersionNumber As String
Dim strDotPosition As String
strVersionNumber = 0
Set saveAs = Application.FileDialog(msoFileDialogSaveAs)
With saveAs
.Title = "Save as"
.InitialView = msoFileDialogViewList
.InitialFileName = Format(Now, "yyyy-mm-dd") & "_" & Mid( _
ActivePresentation.Name, 12) & "V" & _
strVersionNumber + 1 & "_" & ".bas"
If .Show = -1 Then
strFileName = .SelectedItems(1)
ActivePresentation.saveAs (strFileName)
MsgBox "File was succesfully saved."
Else
MsgBox "Saving canceled."
End If
End With
Set saveAs = Nothing
End Sub