Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-20-2022, 10:45 AM
Zach Jennings Zach Jennings is offline Name a new document according to a string it contains Windows 10 Name a new document according to a string it contains Office 2021
Novice
Name a new document according to a string it contains
 
Join Date: Sep 2022
Posts: 1
Zach Jennings is on a distinguished road
Question Name a new document according to a string it contains

Quote:
Originally Posted by macropod View Post
You could add code like the following to each template's 'ThisDocument' module. As coded, it prompts the user to save the file immediately it's created and defaults to whatever path is specified for the StrTmpPath variable and with whatever filename's specified for the StrName variable (which i've coded for the user's name and the system date in ISO format.
Code:
Private Sub Document_New()
Dim StrName As String, StrDefPath As String, StrTmpPath As String
StrName = Environ("UserName") & Format(Now, "YYYYMMDD")
StrTmpPath = "Filepath for documents based on this template"
StrDefPath = Options.DefaultFilePath(wdDocumentsPath)
Options.DefaultFilePath(wdDocumentsPath) = StrTmpPath
With Application.Dialogs(wdDialogFileSaveAs)
  .Name = StrName
  .Show
End With
Options.DefaultFilePath(wdDocumentsPath) = StrDefPath
End Sub
Hey Paul,

This code works wonders form me great job. I have one request though. Is it at all possible to change the code at the strname variable from the user of the system to a string in the actual document. I'm creating a form for my employees to enter clients information and have created a field for the customer name that I want the code to use as the name of the file. If it helps at all I have mapped the customer name to an xml node that i use for filling other fields throughout the document.



Thanks,
Zach Jennings

Last edited by macropod; 09-20-2022 at 02:42 PM. Reason: Split from: https://www.msofficeforums.com/word/11748-add-save-button-form-template.html
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Name a new document according to a string it contains Code to find numerical string + space throughout document & replace them with Comma Robert Kay Word VBA 6 02-21-2018 04:41 PM
Name a new document according to a string it contains How to Import range between two string from other document PRA007 Word VBA 1 12-18-2015 09:23 PM
Name a new document according to a string it contains Way to search for a string in text file, pull out everything until another string? omahadivision Excel Programming 12 11-23-2013 12:10 PM
Replacing text string within document, it's not retaining formatting livemusic Word 4 02-25-2013 12:33 AM
Name a new document according to a string it contains Macro to create new word doc and save the file using String found in the document VBNation Word VBA 2 02-08-2013 07:14 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:43 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