Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

How do I repeat macro action through document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard Winks - 19 Sep 2006 17:43 GMT
It has been asked many times and I can see how to create a loop for the macro
but I do not know how to get the action to start and the beginning and
continue to the end of the active document.

Any help is appreciated.
Dave Lett - 19 Sep 2006 18:34 GMT
What are you trying to loop through or what are to trying to do unitl the
end of the document?

> It has been asked many times and I can see how to create a loop for the
> macro
> but I do not know how to get the action to start and the beginning and
> continue to the end of the active document.
>
> Any help is appreciated.
Richard Winks - 19 Sep 2006 18:48 GMT
I am formatting some text with a macro.  The macro searches for a marker
value "][", inserts a manual line break, selects to the end of the paragraph,
italicizes the selection.

I want to repeat this macro through the entire document.  I'm just not sure
how to go about forming the loop that does this.

Here is the macro code that performs the operation one time.:

Sub AddTTPCommentBreak()
'
' AddTTPCommentBreak Macro
' Macro recorded 9/19/2006
'
   Selection.Find.ClearFormatting
   With Selection.Find
       .Text = "]["
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute
   Selection.TypeText Text:=Chr(11)
   Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
   Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
   Selection.Font.Italic = wdToggle
   Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
Dave Lett - 19 Sep 2006 18:58 GMT
You don't really need a loop for this; instead, you can use a Find/Replace
to handle this.

With Selection
   .HomeKey Unit:=wdStory
   With .Find
       .ClearFormatting
       .Text = "(\]\[)(*)(^13)"
       .MatchWildcards = True
       With .Replacement
           .ClearFormatting
           .Text = "\1^l\2\3"
           .Font.Italic = True
       End With
       .Execute Replace:=wdReplaceAll
   End With
End With

^l (the el letter) is the manual line break. I've put it after the "][".

HTH,
Dave

>I am formatting some text with a macro.  The macro searches for a marker
> value "][", inserts a manual line break, selects to the end of the
[quoted text clipped - 32 lines]
>    Selection.MoveRight Unit:=wdCharacter, Count:=1
> End Sub
Richard Winks - 19 Sep 2006 19:11 GMT
Close enough.  Thanks Dave
Grace - 21 Sep 2006 05:39 GMT
How would i write a loop to replace a page break with a next page section
break?  The next page section break is not one of the items that you can
replace with, a section break is only listed as one of the things you can
find.

> You don't really need a loop for this; instead, you can use a Find/Replace
> to handle this.
[quoted text clipped - 55 lines]
> >    Selection.MoveRight Unit:=wdCharacter, Count:=1
> > End Sub
Richard Winks - 21 Sep 2006 12:31 GMT
Grace,

Use ^m (manual page break) instead of ^l (el) in substitution text.

Dick
Doug Robbins - Word MVP - 21 Sep 2006 21:37 GMT
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
   Do While .Execute(FindText:="^m", MatchWildcards:=False,
Wrap:=wdFindStop, Forward:=True) = True
       Selection.Range.Delete
       Selection.InsertBreak Type:=wdSectionBreakNextPage
   Loop
End With

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> How would i write a loop to replace a page break with a next page section
> break?  The next page section break is not one of the items that you can
[quoted text clipped - 61 lines]
>> >    Selection.MoveRight Unit:=wdCharacter, Count:=1
>> > End Sub
Grace - 17 Oct 2006 15:06 GMT
I created a macro and copied what you had below.  I get a

Compile Error:
Expected: named parameter

message.

> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
[quoted text clipped - 71 lines]
> >> >    Selection.MoveRight Unit:=wdCharacter, Count:=1
> >> > End Sub
Doug Robbins - Word MVP - 17 Oct 2006 19:50 GMT
The mail program has inserted a line break that splits one line of code into
two

The following needs to be all on one line:

    Do While .Execute(FindText:="^m", MatchWildcards:=False,
Wrap:=wdFindStop, Forward:=True) = True

or must have a line break character inserted in the appropriate place

    Do While .Execute(FindText:="^m", MatchWildcards:=False, _
Wrap:=wdFindStop, Forward:=True) = True

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I created a macro and copied what you had below.  I get a
>
[quoted text clipped - 84 lines]
>> >> >    Selection.MoveRight Unit:=wdCharacter, Count:=1
>> >> > End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.