Formatting Word Document with Macros

Andre9570

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

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 comming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier, mine is perriscalderon at gmail
Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...

Forum statistics

Threads
62,036
Messages
673,563
Members
89,037
Latest member
Samhicks