Scripting Help: Formatting Word Document with Macros
I finally have the oportunity to use Macros in Word and I am at a stopping point because of subtle difference in the ways entries are place in a document that i recieve from a company.
I use a macro to search for all instances of a phrase "comment codes" this phrase is preceded by a line that only contain a 4 digit number. I made a basic macro that will shift up one line and delete that line. Now some records will not have that 4 digit number. So I guess I need to put some commands like a If then type, to delete if there is a value on that line otherwise leave it alone. also If I could make it loop until the document is finished it would be helpful.
Here is the code so far:
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 3/18/2004 by Andrew Toro
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Comment Codes:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
End Sub
Thanks for your help
Andrew
I finally have the oportunity to use Macros in Word and I am at a stopping point because of subtle difference in the ways entries are place in a document that i recieve from a company.
I use a macro to search for all instances of a phrase "comment codes" this phrase is preceded by a line that only contain a 4 digit number. I made a basic macro that will shift up one line and delete that line. Now some records will not have that 4 digit number. So I guess I need to put some commands like a If then type, to delete if there is a value on that line otherwise leave it alone. also If I could make it loop until the document is finished it would be helpful.
Here is the code so far:
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 3/18/2004 by Andrew Toro
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Comment Codes:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
End Sub
Thanks for your help
Andrew