• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Formatting Word Document with Macros

#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 posts

Latest profile posts

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 ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,962
Messages
673,247
Members
89,017
Latest member
Seggar