Results 1 to 11 of 11

Thread: Automatic File Naming (Date, Version)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    4
    Location

    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:

    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
    Last edited by Paul_Hossler; 01-02-2018 at 01:39 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •