Formatting Word Document with Macros

Andre9570

Drift On...
Joined
7 Jan 2004
Messages
18
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
 

Members online

No members online now.

Latest profile posts

Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?

Forum statistics

Threads
62,005
Messages
673,461
Members
5,599
Latest member
Larry Chris