Thread: [Solved] Loop Macro to Edit Date
View Single Post
 
Old 11-25-2013, 11:44 AM
damaniam damaniam is offline Windows 8 Office 2013
Novice
 
Join Date: Nov 2013
Posts: 18
damaniam is on a distinguished road
Default

Utilized the forums before but never posted. I've done some excel macros but not certain of the subtle difference between the two. So here's the scenario.

I have a folder that contains about 100 word documents. I'd like the macro to go to this folder select the first file, open it, and search for the ending dates of any month (ie January 31, February 28, March 31...etc), and change it to a specified ending (ex November 30). The specifying process can be handled either through a msg box or through manually editing one line of the code monthly. I'm ok with either. After the macro has opened and edited the document I'd like it printed in adobe to a specified directory. After its done all that I would like the macro to loop on to the next file in the folder containing the word documents. Sorry if this sounds like someone with a hand out, I'm in a bind and its the best way I know to explain my dilemma.

Here is a sample of what I recorded. It is the find and replace portion. The problem I'd like to work around is having one line be edited that would removed the need to place in "Done" for every occurrence. From there its a looping and printing macro and I'm not certain of how to do that in word.

Thanks in Advance
Code:
Sub Macro3()
 '
 ' Macro3 Macro
 '
 '
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
    .Text = "January 31"
    .Replacement.Text = "Done"
    .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 = "February 28"
    .Replacement.Text = "Done"
    .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 = "March 31"
    .Replacement.Text = "Done"
    .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 = "April 30"
    .Replacement.Text = "Done"
    .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 = "May 31"
    .Replacement.Text = "Done"
    .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 = "June 30"
    .Replacement.Text = "Done"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
    .Text = "July 31"
    .Replacement.Text = "Done"
    .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 = "August 31"
    .Replacement.Text = "Done"
    .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 = "September 30"
    .Replacement.Text = "Done"
    .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 = "October 31"
    .Replacement.Text = "Done"
    .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 = "November 30"
    .Replacement.Text = "Done"
    .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 = "December 31"
    .Replacement.Text = "Done"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Last edited by macropod; 11-26-2013 at 07:30 PM. Reason: Added code tags & formatting
Reply With Quote