Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Section Breaks to Page Breaks 1

Status
Not open for further replies.

MacroAlan

Programmer
Dec 4, 2006
135
US
This is my first Word VBA project in a long time.

My Access application sends data to Word for a Mail Merge. The resulting document is a thousand one-page sections. I want to find the section breaks and convert them to Page Breaks.

Code:
Sub ConvertSec2Pages()
    Dim I       As Long
    Dim Secs    As Long
    For I = 1 To ActiveDocument.Sections.Count
        Secs = ActiveDocument.Sections(I).Range.End
        Selection.GoTo what:=Secs  [red]' <-- this does not work[/red]
        Selection.TypeBackspace
        Selection.InsertBreak Type:=wdPageBreak
    Next
End Sub

Can anybody help?? I have been reading the help but don’t seem to know what things are called.


Alan

[smurf]
 
Hi MAcroAlan,

Try:
Code:
Sub ConvertSec2Pages()
Dim i As Integer
With ActiveDocument
    For i = .Sections.Count To 2 Step -1
        .Sections(i).Range.Select
        With Selection
            .Collapse
            .MoveLeft Unit:=wdCharacter, Count:=1
            .Delete
            .InsertBreak Type:=wdPageBreak
        End With
    Next i
End With
End Sub

Cheers

[MS MVP - Word]
 
This helps a lot but I still have a minor problem. If I embed this code in the .DOT (template), it does not break the sections in the merged document.

I tried changing the name to Auto_Open() but apparently the code does not carry over to the merge.

Am I doomed to printing a thousand pages to get one?


Alan

[smurf]
 
My client is not smart enough to run the macro himself.


Alan

[smurf]
 
Hi MacroAlan,

Am I doomed to printing a thousand pages to get one?
How does changing the section breaks to page breaks help? Surely you end up with just as many pages?! If the only problem is that your user wants to print the page(s) from, say, section 15, then the user should learn how to insert 's15' in Word's print dialogue box!!!


As for the automatic running of the macro, I think an AutoNew sub is what you want, instead of AutoOpen, but I'm not sure how these work with mailmerges.

Cheers

[MS MVP - Word]
 
Perhaps if you start at the start.

What...exactly....do you want to happen? Spell it out exactly.

If you are using a .dot file, then use the Document_New event. It is in the ThisDocument code module.

As for the user not being smart enough, I feel of two minds.

1. Then you be smarter and write good code to deal with it.

2. I am with macropod, if th ethe issue is th euser just wants the 15th page, then tell them how to do that.

In any case, maybe if you tell us exactly what the issue is, because, as macropod points out, changing the Section breaks to Page breaks will still have a 1,000 page document. So....exactly...what is it you are trying to do?

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top