Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 09-30-2020, 07:27 PM
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

With Bookmarks named "Invoice" and "Name" in your document and the following macros in the document's template you should get what you want.


Code:
Sub FileSaveAs()
    ' Run as substitute for FileSave to add bookmark contents 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
    '
    On Error GoTo BookMarkMissing
    '
    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)
    Let strName = ActiveDocument.Bookmarks("Invoice").Range.Text & " - " & _
        ActiveDocument.Bookmarks("Name").Range.Text
'    Let 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
        Let .Name = strPath & "\" & strName
        .Show
    End With
    '   Reset save path
    GoTo ResumeProcess
BookMarkMissing:
    MsgBox "It appears that one or more of the bookmarks Name or Invoice is missing."
ResumeProcess:
    Let Application.Options.DefaultFilePath(wdDocumentsPath) = strPath
    '   empty object and reset Error Handler
    Set dlgSave = Nothing
    On Error GoTo -1
End Sub

Sub FileSave()
    FileSaveAs
End Sub

Last edited by Charles Kenyon; 10-01-2020 at 08:59 AM.
Reply With Quote
 



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 01:08 PM.


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