View Single Post
 
Old 01-18-2018, 04:36 AM
Charles Kenyon Charles Kenyon is offline Windows 10 Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,454
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Here is some code that may help. I haven't tested it.

Code:
 Sub FileSave()
      ' Run as substitute for FileSave to add date to default document names
      ' Charles Kenyon 2017
      ' Appends date to Title Document property when saving
          On Error Resume Next
     
      If Len(ActiveDocument.Path) > 0 Then
        ' The document has already been saved at least once.
        ' Just save and exit the macro.
        ActiveDocument.Save
        Exit Sub
      End If
      '
        '
      Dim strName As String, dlgSave As Dialog
      Set dlgSave = Dialogs(wdDialogFileSaveAs)
      strName = ActiveDocument.BuiltInDocumentProperties("Title").Value 'get name in title
      strName = strName & " " & ActiveDocument.ContentControls(2).Range.Text 'add name from second content control
  '   Append current date
      strName = strName & " " & Format((Year(Now() + 1) Mod 100), "20##") & "-" & _
          Format((Month(Now() + 1) Mod 100), "0#") & "-" & _
          Format((Day(Now()) Mod 100), "0#") 'add date
      With dlgSave
          .Name = strName
          .Show
      End With
  End Sub
It would go in the template for your document and assumes the presence of the Content Control. It suggests rather than forces the name.

This also appends a date. That was in the code I'm using so I threw it in. You could comment it out or delete it.

Note this adds a space between the title and the control.

If your second part is a re-purposed document property content control, you could identify it as we did for the Title property.
Reply With Quote