Thread: [Solved] Automated file names
View Single Post
 
Old 04-16-2013, 05:34 AM
OTPM OTPM is offline Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Apr 2011
Location: West Midlands
Posts: 981
OTPM is on a distinguished road
Default

Hi Gary

You could use this macro in your template:

Sub fName()
Dim fName As String
Dim lngStart As Long
Dim lngEnd As Long

'find customer name starting and ending positions
'which will be between the "_" and "." in the file name
lngStart = InStr(ActiveDocument.Name, "-")
lngEnd = InStr(ActiveDocument.Name, ".")

'pull customer name out of the file name
DocNum = Mid(ActiveDocument.Name, lngStart + 1, lngEnd - lngStart - 1)
DocNum = DocNum + 1
TempFileName = Mid(ActiveDocument.Name, 1, lngStart)
ActiveDocument.SaveAs FileName:=TempFileName & DocNum
End Sub

Your filename (in this instance) would be "Test Unique Filename-0" to start with.
Each time the macro is run the document is saved by incrmenting the number at the end of the filename by 1 and saving it in its current location.
You could either add a shortcut to this macro or modify the toolbar in this template by assigning this macro to the SaveButton on the Toolbar.
Hope this helps.
Good luck.
Tony
Reply With Quote