INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

LAST TIME: HOW DO I MAKE THIS MACRO LOOP

LAST TIME: HOW DO I MAKE THIS MACRO LOOP

(OP)
Sorry for not making things clearer in my previous posts and my explanation as to why the problem has not been solved would be too wordy. So I apologize for my previous posts on this and truly appreciate previous input. I finally have this macro perfected like I want. The macro was created in Word and once a document is opened it arrows down twice, finds the word "REPORT", and once it's found, close search window, cursor up one line and press End key to get to the end of that line then Ctrl-Enter to force a page break. Please tell me exactly what and where to put it into this macro to make it keep running until the end of the file and stop. Thank you so much. Here is the code:

Sub Macro1()
'
' Macro1 Macro
'
'
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "REPORT"
.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.EndKey Unit:=wdLine
Selection.InsertBreak Type:=wdPageBreak
Selection.MoveDown Unit:=wdLine, Count:=2
End Sub

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

How about uploading a sample Word document that has all the stuff in it that this macro needs.

Also state what the finished product should look like page break wise.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

You still show no evidence that you've actually tried what you've already been given. IMHO you're just wasting everyone's time...

Cheers
Paul Edstein
[MS MVP - Word]

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

strongm's suggestion in the previous threads does exactly this albeit with less screen flickering and much faster.
Have you tried it?
If so: what exactly does it NOT do the way you want it to?

Quote:

once a document is opened
have you tried putting it in a module in your document like this

CODE -->

Sub AutoOpen()
...
End Sub 
?

P.S: Please respond here, do not open yet another thread, especially not all-caps or with an added "!Arghhh!" yinyang

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

Here's your macro (it's just a find/replace that you really don't need to code as a macro):

CODE -->

Sub Annual_Report()

'
' Annual_Report Macro
'
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = _
            "^p                                             ANNUAL REPORT "
        .Replacement.Text = "^m^&"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub 

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

Quote:

You have repeatedly stated that REPORT was the key word, but it is NOT! Your requirement is incorrect!
Actually, tombaraider specified it as 'Report', but the document has 'REPORT', which makes all the difference with a wildcard Find/Replace. Whether it's 'REPORT' or 'ANNUAL REPORT' makes no difference for the F/R unless one needs to differentiate between the two. It can all be done with a wildcard Find/Replace, where:
Find = (^13)([!^13]@REPORT@[^13])
Replace = \1^012\2
or:
Find = (^13)([!^13]@ANNUAL REPORT@[^13])
Replace = \1^012\2

No macros or loops required! Of course, if tombaraider really, really, really wants a macro, there's always the macro recorder...



Cheers
Paul Edstein
[MS MVP - Word]

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

Right, so a very, very minor modification to the code I presented to you earlier works with your new criteria. As with macropod's solution it still does not need a loop.

CODE

Selection.Find.Replacement.ParagraphFormat.PageBreakBefore = True
With Selection.Find
    .Text = "report"
    .Replacement.Text = ""
    .Forward = True
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll 

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

Well, the OP code at the very beginning of this thread does something different.
I actually opened a word document, typed =rand() to get some sample text, 'sprinkled' some 'REPORT' words in it and tried the macro.

Yes, it does Find on the word "REPORT", but then
  • moves the cursor one line up
  • moves the cursor to the end of the line
  • inserts a page break
  • moves the cursor 2 lines down
That's a different action that simply "replace word REPORT with a PageBreak"...

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

I apologize. blush

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

Like many things, there's more than one way to skin a cat. Unfortunately, the OP was not clear on what they needed, nor that helpful on the format of the document. If they had provided the examples of the before and after like they finally did, this would have been solved on day 1 with minimal issues and only 1 forum topic instead of 3.

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

(OP)
zeglar your code worked perfectly for the file that I posted. But please understand that this file has been altered to protect confidential information. I only put the word "ANNUAL" before "REPORT" in the document. So please disregard "ANNUAL". In the real document there is another word that preceeds "REPORT" but let's forget about that word. The macro needs to find occurrence of "REPORT" then proceed from there. Please see my original post here for clearest instructions that will work in any document structured like this where only REPORT needs to be found. Thank you so much.

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

(OP)
BTW, I am NOT A CODER. The macro is being recorded in Word. Of course, I can tweak it in VBA.

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

And my code doesn't care what the word is. Do you actually try any of the suggestions? Or just the first one that catches your eye?

>Of course, I can tweak it in VBA.

You've been given several VBA solutions that only require minor tweaking between your changes of requirements. So tweak ...

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

(OP)
Actually strongm I tried your solution next, and it worked like a charm. In fact, so well I sent it to my client and am waiting for his response. After I got the OK from him I was going to post my appreciation to you. And I thank you so much. When I was younger I used to relate with unnecessary attitude. And it was so damn easy. I am more peaceful and respectful now, knowing that many times there is more to something than just our perception. But I must say that there are those who think they provided me with the solution but actually did not through misunderstanding. As you know reading and presenting textual info is far different and ambiguous that talking. My steps in the first post here are flawless in explaining what I needed. And thanks again to you. If my client (and that's another variable in this equation) likes your solution, I must say you have made my day.

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

(OP)
zeglar, At first I blew off posting my files because of the info in them and so as not to get myself in trouble. When I was finally left with no choice I did the busywork of doctoring the file. If this was not the case, I would have posted only one thread and got my solution faster. Nevertheless, I know now how to keep things to one thread. Thanks for your time and attention.

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

Quote:

I must say that there are those who think they provided me with the solution but actually did not through misunderstanding.
No, the problem was you specified something other than what you actually required. Don't try to shift the blame to anyone else.

Cheers
Paul Edstein
[MS MVP - Word]

RE: LAST TIME: HOW DO I MAKE THIS MACRO LOOP

(OP)
strongm my client confirmed today that your solution worked perfectly. I am sure other solutions were valid, too. Many thanks to you and to all who offered assistance and endured my confusion.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close