Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 09-29-2020, 09:11 AM
Charles Kenyon Charles Kenyon is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,584
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

The key language in the following macro is:
Code:
    strName = strName & " " & ActiveDocument.ContentControls(1).Range.Text 'add name from first content control

Here is a pair of macros that I use:


Code:
Sub FileSaveAs()
    ' Run as substitute for FileSave to add date to default document names
    ' Charles Kenyon 2017, 2019, 2020
    ' 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
    Dim strPath As String   'Holder for current path
    Let strPath = Application.Options.DefaultFilePath(wdDocumentsPath)
    Set dlgSave = Dialogs(wdDialogFileSaveAs)
    strName = ActiveDocument.BuiltInDocumentProperties("Title").Value 'get name in title
    strName = strName & " " & ActiveDocument.ContentControls(1).Range.Text 'add name from first content control
    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 = strPath & strName
        .Show
    End With
    '   Reset save path
    Let Application.Options.DefaultFilePath(wdDocumentsPath) = strPath
    '   empty object
    Set dlgSave = Nothing
End Sub

Sub FileSave()
    FileSaveAs
End Sub

This grabs the Title from document properties and adds the content of the first content control in the document and then the date.
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a template with repeat of fields and user input jhansrod Word VBA 0 06-13-2019 08:03 AM
Linking Specific text fields in PP to specific cells in an Excel table GWRW1964 PowerPoint 0 02-26-2018 07:37 AM
Save File with specific name from fields input. How do I update all fields from a new input Kozzzle Word 7 10-19-2017 06:12 PM
Help with Macro to Save Word File as PDF in Specific Location ekimisme Word VBA 1 06-07-2017 10:40 PM
Save Excel file with specific cell value by using VBA code IAMCHEESE Excel Programming 1 11-02-2016 07:11 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft