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

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?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!

Forum statistics

Threads
61,999
Messages
673,424
Members
5,593
Latest member
moussa021