find and replace loop based on dates

Joined
Jun 15, 2012
Messages
5
Reaction score
0
Every month I have to generate play list xml files. They all contain the same content. The only thing that changes is the date. Currently I am just doing a find and replace and saving the document. I did record a macro to do this but it is a very long code. Can someone help me create a find and replace loop for this job. Sample of the code is below:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "07-02"
.Replacement.Text = "07-03"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "07-01"
.Replacement.Text = "07-02"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ChangeFileOpenDirectory "C:\Documents and Settings\jayjohn1984\Desktop\TESTS\Schedules\July"
ActiveDocument.SaveAs FileName:="07_02_Schedule.xml", FileFormat:=wdFormatFlatXML, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False

The next find and replace would be:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "07-03"
.Replacement.Text = "07-04"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "07-02"
.Replacement.Text = "07-03"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ChangeFileOpenDirectory "C:\Documents and Settings\jayjohn1984\Desktop\TESTS\Schedules\July"
ActiveDocument.SaveAs FileName:="07_03_Schedule.xml", FileFormat:=wdFormatFlatXML, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False

And so on and so forth until the end of the month. Can someone please help me out with this.

Thanks!
 
Back
Top