View Single Post
  #3   Report Post  
Posted to microsoft.public.word.pagelayout
StevenM StevenM is offline
external usenet poster
 
Posts: 20
Default Problems creating Macros

Assuming you need more than one page setup, you might try modifing the
following to your needs. If you only need one page setup, you should create a
new template.

Sub TestPageSetup()
Dim nColumns As Long
Dim pColWidth As Single
Dim pColGutter As Single
Dim pTop As Single
Dim pBottom As Single
Dim pLeft As Single
Dim pRight As Single
Dim pWidth As Single
Dim oRange As Range
Dim footerRange As Range

pTop = 6
pBottom = 6
pLeft = 6.5
pRight = 6.5
pColGutter = 3
nColumns = 2
pColWidth = (51 - (pColGutter + pRight + pLeft)) / nColumns

Set oRange = ActiveDocument.Range(Start:=ActiveDocument.Range.S tart,
End:=ActiveDocument.Range.End)

With oRange.PageSetup
.TopMargin = PicasToPoints(pTop)
.BottomMargin = PicasToPoints(pBottom)
.LeftMargin = PicasToPoints(pLeft)
.RightMargin = PicasToPoints(pRight)
End With

With oRange.PageSetup.TextColumns
.SetCount NumColumns:=nColumns
.EvenlySpaced = True
.LineBetween = False
.Width = PicasToPoints(pColWidth)
.Spacing = PicasToPoints(pColGutter)
End With

Set footerRange = oRange.Sections(1).Footers(wdHeaderFooterPrimary). Range

With footerRange
.Delete
With .ParagraphFormat.TabStops
.ClearAll
pWidth = 51 - (pLeft + pRight)
.Add Position:=PicasToPoints(pWidth / 2),
Alignment:=wdAlignTabCenter
.Add Position:=PicasToPoints(pWidth), Alignment:=wdAlignTabRight
End With
.InsertAfter vbTab & vbTab & "Page "
.MoveEnd unit:=wdCharacter, Count:=1
.Collapse wdCollapseEnd
oRange.Fields.Add Range:=footerRange, Type:=wdFieldPage
.MoveEnd unit:=wdCharacter, Count:=1
.Collapse wdCollapseEnd
.InsertAfter vbCr
End With
End Sub


"Gabe" wrote:

I'm trying to create a macro to change my margins, make a document have 2
cols., and insert a page number at the end of the page using a keybord
command.
No matter how I try or which order I try these steps, I get the debug error
5941.
I don't know what that means, I don't know what i've done wrong.

Can anybody help?

Thanks,

Gabe