Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #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
  #2  
Old 09-20-2022, 02:45 PM
macropod's Avatar
macropod macropod 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 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You wouldn't be able to do that via a Document_New macro, since your save string wouldn't exist immediately the document is created. One would have to wait until the user attempts to save the document for the first time.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-20-2022, 03:40 PM
Guessed's Avatar
Guessed Guessed 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 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Zach
I think Paul misunderstood your question. Yes you can use a string (or xml value) from your actual document. You haven't provided enough details in order for us to give you the actual code update.

As an example since you are using xml mapping, you might want the contents of the first Content Control in the document to be part of the filename.
Code:
StrName = ActiveDocument.ContentControls(1).Range.Text & Format(Now, "YYYYMMDD")
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Thread Tools
Display Modes


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 04:10 AM.


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