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

change margin on 2nd page only 1

Status
Not open for further replies.

lemonhalls

Technical User
Jun 11, 2004
52
CA
Currently I have this code to change the margin of the entire doc.

With ActiveDocument.Range(Start:=Selection.Start, End:=ActiveDocument. _
Content.End).PageSetup
.LeftMargin = CentimetersToPoints(1.3)
End With

But I would like to change the margin on the TOC page only by using

With activeDocument.Sections(2).PageSetup.LeftMargin = CentimetersToPoints(0.8)

But this latter code seem to change the margin of all the pages there after.

How do I get this margin change to apply to the second page only?

Thanks
 
Hi S. Try recorong a macro for each section. which is what I was going to send you.

By making your target documernt have explicit sections, you can change margins for explicit sections. When you record changing the pagesetup, there is a drop down box on the pagesetup, The choices are; Whole document. This Section, and This section forward.

For section 1 (the cover page) - make it this section only; For section 2 (the ToC) - make it this section only; for section 3 - make it This section forward. That way you can have different margin per section. Which is what you want.


Gerry
 
gerry,

there's a section break after the last entry on the TOC.
then the first file gets inserted there after.

I recorded the macro and got
With Selection.PageSetup
.LeftMargin = CentimetersToPoints(0.9)
.RightMargin = CentimetersToPoints(1.4)
End With

I put it at the end of my TOC code, but it is adjusting the margin for the TOC page and the first inserted file, but there after, every thing else is as is, following this code at the beggining I think:

With ActiveDocument.Range(Start:=Selection.Start, End:=ActiveDocument. _
Content.End).PageSetup
.LeftMargin = CentimetersToPoints(1.3)
End With

how do i get the first inserted file to have the same margin as the rest of doc?
 
You are still using the Selection object. STOP.

Follow through section by section.

I do not know if have made the changes I suggested, but think this one through.

You have your first page...nothing else.

do your pagesetup (margins , whatever) for that section, the cover page.

Make a new section (this is for your ToC). If they are different from the cover page section, fine, do another pagesetup, and have it apply to THIS SECTION. If they are NOT different from the coverpage section - forget about it.

Remember this is happening BEFORE any files are being copied in. Please stop refering to them being inserted in - they are not being inserted, they are being copied (that is if you changed your code to what I wrote).

Then you make a new section. This is the starting section (#3 now) for your content you are copying in. Do another pagesetup. This time make it to apply from This Section Forward. If you want to add the filename of the source file that is filling the content of each content section, then add SFile in the footer.

This is also where you START your page numbering. On this first section (but #3 in the collection), I think you want to start page numbering at 1. So, go Page Numbering, Section, start from 1. Do know know how to do that?

Please look up Help on the Selection object, or if you want, I have some documentation for a VBA course I am writing regarding the Selection object. I could send it to you. For example:

Currently I have this code to change the margin of the entire doc.

With ActiveDocument.Range(Start:=Selection.Start, End:=ActiveDocument. _
Content.End).PageSetup
.LeftMargin = CentimetersToPoints(1.3)
End With[/code}

This is absolutely incorrect. It will NOT, repeat, NOT change the entire document. Well it would but ONLY, repeat ONLY, if the selection point is at the very first character of the document. Look at the code. The range being affected is Range(Start:=Selection.Start,.

It will afect from the selection point to the end of the document. If the selection point is on page 12 of a 13 page document....the only thing affected is from, well the selection point to the end of the document. ie. page 12 and 13.

You got that from my code. Read it again. That code ran, right after the first section break was inserted, after the cover page. I did not want to assume that the margins were the same for the cover page. Cover pages are tricky, and usually have their own page setup. So I ran that to affect margins, from that point onwards. If you run it with the ToC routine, then it will afect the ToC section.

With ActiveDocument
.PageSetup.LeftMargin blah blah
.bla blah
End With

DOES affect the whole ActiveDocument.

With ActiveDocument
.Range(Start:=Selection.Start, _
End:=ActiveDocument. _
Content.End)
.PageSetup.LeftMargin blah blah
.bkah blah
End With

affects everything from the selection point to the end of the document. And the selection point at the time you seem to be running this code is NOT at the beginning of the document, or even at the beginning of the section you want to apply this to.

Gerry
 
Yes Gerry, please send me info from your vb course! I'd love to read more about it!

With ActiveDocument
.Range(Start:=Selection.Start, _
End:=ActiveDocument. _
Content.End)
.PageSetup.LeftMargin blah blah
.bkah blah
End With

I did see this from your code, it was the same as the macro I recorded. I put this code as part of the mergeDoc code, which is where the 3rd section begins!?

By making a new section, you mean inserting a section break right? If so, this is indeed what I did. Each file starts at a new section.

The margin is being applied to 2nd and 3rd section only. Why????
 
I suspect you are running the ToC routine at the wrong time. In one of your other posts, I wrote the order in which it should go.

1. Cover page followed by a section break
2. a bookmark to mark where you WILL put the ToC.
3. section break
4. file gathering code
5. when all the file gathering is done; run the ToC routine.

The ToC routine, does the ToC generation , and sets the margins from Selection Start to the end of the document, which will, as you want it, make all the rest of the document set with those margins.

As I pointed out;

With ActiveDocument
.Range(Start:=Selection.Start, _
End:=ActiveDocument. _
Content.End)
.PageSetup.LeftMargin blah blah
.bkah blah
End With

affects from the Selection start to the end of the document...at the time the code is run. If you put more stuff at the end of of the document, after you run the code...it will not rerun itself. It does its thing and stops. It is gone. Over. Anything added to the end is NOT affected.

In your original code you generated the ToC before all your content was in place. Try putting it at the end.

Gerry
 
Hi Gerry!

I rearranged the code, and added a section break now it works!! YEA ~ thanks a million for being so patient and your help.

S =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top