How to do an instruction in all pages with macros

J

Jose Manuel

Hi!

I'm trying to repete this instruction in all pages:

Dim paginas As String
paginas = 1
Do
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.InsertBreak Type:=wdPageBreak
paginas = paginas + 1
Loop Until paginas = PAGE_TOTAL!!

End Sub

My doubt is how to define the PAGE_TOTAL. In the documents I work with, the
number of pages is not fixed, so it's tired to change the total each time I
use the macro.

Is there another way to do this simpler? Is there a function to get the
total of pages?

Thanks a lot!
 
B

Beth Melton

What are you attempting to do exactly? I mean, I know you are moving down a
line, deleting a character, inserting a page break, etc. but please describe
what you are trying to accomplish. I suspect a different method can be used.

~Beth Melton
Microsoft Office MVP
 
J

Jose Manuel

Hi Beth.

What I´m trying to do is to replace all section breaks for page breaks.

My problem is that after using the tool for combining correspondence, word
inserts a section break after every page, and I need no breaks. I'd like to
change all of them for page breaks.

Thanks a lot!
 
S

Suzanne S. Barnhill

Before you do this, make very sure that no letter has more than one page (or
that the pages aren't numbered or don't have a letterhead in the First Page
Header). Word has very good reasons for separating mail-merged letters with
section breaks.

FWIW, you should be able to replace section breaks with page breaks by
searching for ^b and replacing with ^m.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
B

Beth Melton

I had a feeling it was something simple. All you need is Find and Replace.
:)

In the Find and Replace (F5) dialog box use:
Find What: ^b
Replace With: ^m
Replace All

You can find various special codes when you click the "More" button in the
Find and Replace dialog box and then click Special.

~Beth Melton
Microsoft Office MVP
 
J

Jose Manuel

worked perfecly! Thanks a lot!



Beth Melton said:
I had a feeling it was something simple. All you need is Find and Replace.
:)

In the Find and Replace (F5) dialog box use:
Find What: ^b
Replace With: ^m
Replace All

You can find various special codes when you click the "More" button in the
Find and Replace dialog box and then click Special.

~Beth Melton
Microsoft Office MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top