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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting blank page

Status
Not open for further replies.

lemonhalls

Technical User
Jun 11, 2004
52
CA
I have a cover page to start and am trying to write a macro to insert the toc to the second page.

I currently have a bookmark at the beginning of the second page and I start off my document with a blank second page which is not very pleasant.
______________________
Sub locateSecondPage()
ActiveDocument.Bookmarks("\EndOfDoc").Copy "currpara"
ActiveDocument.Bookmarks("currpara").Select
End Sub

I would like to write the code to tell it to insert a blank page after the current page but not sure about the syntax.

Any help will be appreciated. Thanks in advance!
 
Have you tried the macro recorder ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Not sure you are going about this the right way.

Sub locateSecondPage()
ActiveDocument.Bookmarks("\EndOfDoc").Copy "currpara"
ActiveDocument.Bookmarks("currpara").Select
End Sub

The name of this is "locateSecondPage", but is it really locating it?

It appears the bookmark you refer to is "\EndofDoc". You copy "currpara" - which is what? Then you select that bookmark. This does not locate the second page. So I am not sure what exactly you are doing here. There is no Go To the bookmark, so it is not really "locating" it.

The following (run from a page, any page) will make a section break to a new page and insert a TOC. Have you tried recording a macro?

Code:
Sub NewPageWithToC()
'
    Selection.InsertBreak Type:=wdSectionBreakNextPage
    With ActiveDocument
        .TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
            True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
            LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:="", _
            UseHyperlinks:=False, HidePageNumbersInWeb:=True, UseOutlineLevels:= _
            True
        .TablesOfContents(1).TabLeader = wdTabLeaderDots
        .TablesOfContents.Format = wdIndexIndent
    End With
End Sub

These are the default setups for a TOC (although I did change hyperlinks to false. You will likely need to alter things, especially if you are using particular styles for headings.

It is not clear in your post, but I suspect the case is this. You have a document, and you are adding a cover page, followed by a TOC. If so, add a further section break to the code to separate the TOC from the body of the document. Just repeat the first line at the end of the code.

If you post a bit more information as to precisely what you are trying to do, perhaps we could help more.



Gerry
 
Gerry, PHV,

Thanks for the tip!
You're right, I should have tried recording first. I am not very familiar with the manual process of creating a TOC, hence recording a macro didn't come into my mind. =(
Surely, I will try it first next time!

Gerry,
The code works wonderfully!

lemonhalls - S
 
Glad I Could help. There is nothing like a fresh of breath air.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top