There's no such thing as a stupid question, but they're the easiest to answer.


Business Applications Business Applications
Search Search
Search for:
Tech Support Guy > > >

Word Macro: How to keep macro running until end of page is reached


HowdeeDoodee's Avatar
HowdeeDoodee HowdeeDoodee is offline
Member with 606 posts.
Join Date: Aug 2004
Experience: Intermediate
06-Jun-2008, 06:24 AM #1
Word Macro: How to keep macro running until end of page is reached
How do you keep a macro running until you reach the end of a page? Currently I just hold down the control or Alt keys. I have long documents so holding down the Alt + whatever key is not always practical.

Here is a sample macro. How do I make the macro run until the macro reaches (in this case) the top of the page?

I think the "do until" feature is used in the code but I do not know the syntax for "do until".

Sub DelimitBoldSentenceOnRightWithATab()
Selection.Find.Font.Bold = True
With Selection.Find
    .Text = "*"
    .Replacement.Text = ""
    .Forward = False
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = True
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.TypeText Text:=vbTab & vbTab
Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=vbTab & vbTab
Selection.MoveLeft Unit:=wdCharacter, Count:=3

End Sub
Thank you in advance for your replies.
Rollin_Again's Avatar
Member with 4,726 posts.
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Advanced
06-Jun-2008, 10:35 AM #2
You can evaluate the current page number using the following property:


Just use a loop and have it execute while Selection.Information(wdActiveEndPageNumber) = 1

Can you post your sample document?

HowdeeDoodee's Avatar
HowdeeDoodee HowdeeDoodee is offline
Member with 606 posts.
Join Date: Aug 2004
Experience: Intermediate
06-Jun-2008, 10:59 AM #3
Hi Rollin. Thank you for the reply. You have helped me before. Good to see you again.

Here is only a tiny snippet of one of the documents. Most documents are 1400 - 1800 pages. The snippet below shows the document before I do any processing on it. In the processing sequences, I do the documents both from the bottom of the document up and from the top down (different documents and different macros of course). I would like basic strategy on where to put the loop since differnt macros are going to have different code.


Psa 51:5 -

Behold, I was shapen in iniquity - A genuine penitent will hide nothing of his state; he sees and bewails, not only the acts of sin which he has committed, but the disposition that led to those acts. He deplores, not only the transgression, but the carnal mind which is enmity against God. The light that shines into his soul shows him the very source whence transgression proceeds; he sees his fallen nature, as well as his sinful life; he asks pardon for his transgressions, and he asks washing and cleansing for his inward defilement. Notwithstanding all that Grotius and others have said to the contrary, I believe David to speak here of what is commonly called original sin; the propensity to evil which every man brings into the world with him, and which is the fruitful source whence all transgression proceeds. The word חוללתי cholalti, which we translate shaped, means more properly, I was brought forth from the womb; and יחמתני yechemathni rather signifies made me warm, alluding to the whole process of the formation of the fetus in utero, the formative heat which is necessary to develope the parts of all embryo animals; to incubate the ova in the female, after having been impregnated by the male; and to bring the whole into such a state of maturity and perfection as to render it capable of subsisting and growing up by aliment received from without. “As my parts were developed in the womb, the sinful principle diffused itself through the whole, so that body and mind grew up in a state of corruption and moral imperfection.”


Psa 51:6 -

Behold, thou desirest truth - I am the very reverse of what I should be. Those desirest truth in the heart, but in me there is nothing but sin and falsity.
Thou shalt make one to know wisdom - Thou wilt teach me to restrain every inordinate propensity, and to act according to the dictates of sound wisdom, the rest of my life.


Psa 51:7 -

Purge me with hyssop - תחטאני techatteeni, “thou shalt make a sin-offering for me;” probably alluding to the cleansing of the leper: Lev_14:1, etc. The priest took two clean birds, cedar-wood, scarlet, and hyssop; one of the birds was killed; and the living bird, with the scarlet, cedar, and hyssop, dipped in the blood of the bird that had been killed, and then sprinkled over the person who had been infected. But it is worthy of remark that this ceremony was not performed till the plague of the leprosy had been healed in the leper; (Lev_14:3); and the ceremony above mentioned was for the purpose of declaring to the people that the man was healed, that he might be restored to his place in society, having been healed of a disease that the finger of God alone could remove. This David seems to have full in view; hence he requests the Lord to make the sin-offering for him, and to show to the people that he had accepted him, and cleansed him from his sin.

Thank you again for the response.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

You Are Using: Server ID
Trusted Website Back to the Top ↑