View Full Version : Advance 1 year forward....
JohnnyBravo
02-16-2006, 09:26 AM
I'm working on several templates our company uses year after year. The contents are the same. The only thing that changes is the year. For example in one part of the document, it might say: List the volumes for 2003, 2004, 2005. And then the user will have to enter the volumes for those years in a table cell. However, sometimes they are not in a table cell.
At any rate for next year, I need the document to read:
List the volumes for 2004, 2005, 2006
There are about 20 templates in all that I need to modify. So I would like to run a macro so that whatever year is found in the document, it advances it one year forward per the example above.
mdmackillop
02-16-2006, 09:56 AM
Are all the templates in one folder. or can you create a list in a table of all the template paths and names?
Is there any possibility of the year values appearing as data values eg ?2005?
JohnnyBravo
02-16-2006, 10:26 AM
Are all the templates in one folder. or can you create a list in a table of all the template paths and names?
They are located in various folders saved on our network. I suppose I could create a list of the documents and the folder path; but I was thinking i could just open up the documents myself and then run a macro that runs for "Active Document" only.
Sounds like what you're saying is that if I were to create such a list, the VBA macro could retrieve those documents automatically and make the changes.
Is there any possibility of the year values appearing as data values eg ?2005?
No.
mdmackillop
02-16-2006, 10:54 AM
Try the attached file, which incorporates the code listed below. If you want to do them individually, then open the template and run the DoDates macro.
Regards MD
Sub Updates()
Dim i As Long, cel
Application.ScreenUpdating = False
For i = 1 To ActiveDocument.Tables(1).Range.Cells.Count
cel = ActiveDocument.Tables(1).Cell(i, 1)
cel = Left(cel, Len(cel) - 2)
Documents.Open FileName:=cel, ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto, XMLTransform:=""
DoDates
MsgBox cel & " updated"
ActiveDocument.Save
ActiveDocument.Close
Next
Application.ScreenUpdating = True
End Sub
Sub DoDates()
Dim OldD, NewD, i As Long
OldD = Array(2006, 2005, 2004)
NewD = Array(2007, 2006, 2005)
For i = 0 To 2
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = OldD(i)
.Replacement.Text = NewD(i)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
End Sub
JohnnyBravo
02-16-2006, 11:43 AM
Thanks for that but I have a question for you. The example I gave above isn't always the case for every single template. In another words, It's not always going to be 2003, 2004, 2005 together in one sentence. Some paragraphs (depennding on the document) may just say 2005.
I see you've got the years listed as an Array according to your VBA routine. Will that still work for the situation I've described??
mdmackillop
02-16-2006, 11:52 AM
It seems OK in my simple tests. I would copy a couple of templates and test it on them to be sure.
JohnnyBravo
02-27-2006, 09:05 AM
mdmackillop, what is the difference between the 2 macros above? I ran the DoDates routine, but don't quite understand what the Updates routine does. Does the "Updates" routine handle only those that are in a table cell? Is that why you wrote a separate macro for it?
On a side note, I tried to mark this thread as solved and can no longer find the 'Thread Solved' option here.
mdmackillop
02-27-2006, 10:39 AM
For bulk changes, list the templates (full path name as per the example) to be changed within a table and run Updates. This will run the DoDates macro on all listed templates. To run the update a single template, open it and run the DoDates macro.
The "Solved" button has disappeared during the upgrade. Hopefully it will be back soon.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.