Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2016, 02:46 PM
Andkins Andkins is offline Word file naming macro Windows 7 32bit Word file naming macro Office 2007
Novice
Word file naming macro
 
Join Date: Oct 2016
Posts: 1
Andkins is on a distinguished road
Default Word file naming macro

I have a Word document that my team uses as a template for letters to clients. The file name is the same as the name of a related PDF document but with an added suffix or two.



It's easy to copy the PDF file name and paste it as the Word file name then add the suffix, but is there a way to program Word to pull that information automatically? The suffix is the author's initials, and sometimes another code, so it has to be added manually.

Additionally, or perhaps alternatively, a couple fields in the letter repeat information in the file name. The file name is always Recipient_ClaimNumber_InvoiceNumber, and the letter has fields for the claim and invoice number. (The underscores are part of the file name.) Is it possible to populate those fields in the letter by drawing from the file name? Is it easier to have the file name draw from the letter? The Recipient part of the file name is a short version of a longer name used in the letter, and does not consistently reflect the recipient name.

I don't know anything about programming or macros, so I'll need as much patience and detail as you can give me. I'm trying to learn how to expand beyond the basic elements of Office programs. Thanks for your help and guidance.
Reply With Quote
  #2  
Old 10-15-2016, 08:58 PM
gmayor's Avatar
gmayor gmayor is offline Word file naming macro Windows 10 Word file naming macro Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,707
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

I have a feeling that you are approaching this from the wrong angle. Do we take it that you are using an existing document and renaming it for each new letter? If so, don't!

Save the letter as a template and create new letters from it. By saving it as a macro enabled template you can save any macros that the template needs in the template itself.

You say that the filename is the same name as the name of a related PDF, but you don't say what the relationship to the PDF is. You cannot automate the filename from the PDF if the macro that does the naming knows nothing about the PDF.

The initials can usually be derived from the Username (see below), but if the users have names with e.g. suffixes or titles, a lookup might be simpler than catering for each individual option.

The shortened recipient name can probably be derived from the recipient name, but you have not explained how it is shortened, or if it is shortened in a consistent manner.

Where do the Claim number and Invoice number come from? Are they manually input? If so, it would make sense to create a useform, that fires when you create a new document from the template. The userform would collect the variable data used in the template and write it to the document either using bookmarks or docvariable fields to position the data in the letter. It would also assemble the filename and save the document. The PDF however remains an unknown quantity.

See http://www.gmayor.com/Userform.htm which covers the basic principles. You will also find the FillBM function on my web site, that will write a value to a bookmark.

If you want any assistance over the detail than you will need to provide more information.
Code:
Option Explicit

Function GetInitials() As String
Dim sInitials As String: sInitials = ""
Dim vName As Variant
Dim i As Long
    vName = Split(Environ("Username"), Chr(32))
    For i = 0 To UBound(vName)
        sInitials = sInitials & Left(Trim(vName(i)), 1)
    Next i
    GetInitials = sInitials
lbl_Exit:
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to put 1 word of a MS Word file in 1 cell of a Word or Excel Table Singh_Edm Word VBA 6 11-13-2015 08:48 PM
Macro to highlight repeated words in word file and extract into excel file aabri Word VBA 1 06-14-2015 07:20 AM
Auto file naming Rong Peng Word VBA 0 07-29-2011 07:37 AM
Word file naming macro Word Macro: Save file as text with current file name jabberwocky12 Word VBA 2 10-22-2010 12:23 PM
Auto-File Naming/ Default Directory Saves sgill32 Word 2 11-06-2008 02:12 PM

Other Forums: Access Forums

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


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