babsiee
03-12-2013, 09:27 AM
Hi all!
I have made a macro. It helps me to add images in the headers and text in the footers. With a different first page. It also changes the marges of the page.
It works fine when I use it on an empty document. But when I use it on a document with text already in it, it goes wrong.
Then it adds the logo, that needs to be in the header of the second page, underneath the logo of the first page!
Any ideas how to solve this?
Thanks!
Babette
Sub MacroB()
'
' MacroB Macro
'
' Custom form page parameters
Const FPageWid = 7: Const FPageHgt = 2#
Const FMargLft = 1: Const FMargRgt = 0.78
Const FMargTop = 1.77: Const FMargBot = 0.78
' Word page dimensions
Const WPageWid = 8.5: Const WPageHgt = 11
' Printer no-print area
Const PNoPrTop = 0.25: Const PNoPrBot = 0.25
Const PNoPrLft = 0.25: Const PNoPrRgt = 0.25
Dim WMargTop, WMargBot, WMargLft, WMargRgt ' Word margins
WMargTop = FMargTop
WMargBot = FMargBot
WMargLft = FMargLft
WMargRgt = FMargRgt
Dim oDoc As Document
Dim oVars As Variables
Set oDoc = ActiveDocument
Set oVars = oDoc.Variables
With oVars
.Add("WMargTop").Value = WMargTop
.Add("WMargBot").Value = WMargBot
.Add("WMargLft").Value = WMargLft
.Add("WMargRgt").Value = WMargRgt
End With
With oDoc.PageSetup
.TopMargin = InchesToPoints(oVars("WMargTop").Value)
.BottomMargin = InchesToPoints(oVars("WMargBot").Value)
.LeftMargin = InchesToPoints(oVars("WMargLft").Value)
.RightMargin = InchesToPoints(oVars("WMargRgt").Value)
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Dialogs(wdDialogInsertPicture)
.Name = "http://www.broesj.com/Kop4.jpg"
.FloatOverText = False
.Execute
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.TypeText Text:="here is text"
Selection.MoveLeft Unit:=wdCharacter, Count:=192, Extend:=wdExtend
Selection.Font.Name = "Verdana"
Selection.Font.Size = 6
ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
Dim asection As Section
Set asection = Selection.Sections(1)
With asection
With .PageSetup
End With
'tekst header pagina 1
ActiveWindow.ActivePane.View.SeekView = wdHeaderFooterFirstPage 'HEADER PAGINA 1
With Dialogs(wdDialogInsertPicture)
.Name = "http://www.broesj.com/Kop3.jpg"
.FloatOverText = False
.Execute
End With
'footer lettertype enzo
.Footers(wdHeaderFooterFirstPage).Range.Text = "here is text"
ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage).Range.Select
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Name = "Verdana"
Selection.Font.Size = 6
ActiveWindow.ActivePane.View.Type = wdPageView
End With
End Sub
I have made a macro. It helps me to add images in the headers and text in the footers. With a different first page. It also changes the marges of the page.
It works fine when I use it on an empty document. But when I use it on a document with text already in it, it goes wrong.
Then it adds the logo, that needs to be in the header of the second page, underneath the logo of the first page!
Any ideas how to solve this?
Thanks!
Babette
Sub MacroB()
'
' MacroB Macro
'
' Custom form page parameters
Const FPageWid = 7: Const FPageHgt = 2#
Const FMargLft = 1: Const FMargRgt = 0.78
Const FMargTop = 1.77: Const FMargBot = 0.78
' Word page dimensions
Const WPageWid = 8.5: Const WPageHgt = 11
' Printer no-print area
Const PNoPrTop = 0.25: Const PNoPrBot = 0.25
Const PNoPrLft = 0.25: Const PNoPrRgt = 0.25
Dim WMargTop, WMargBot, WMargLft, WMargRgt ' Word margins
WMargTop = FMargTop
WMargBot = FMargBot
WMargLft = FMargLft
WMargRgt = FMargRgt
Dim oDoc As Document
Dim oVars As Variables
Set oDoc = ActiveDocument
Set oVars = oDoc.Variables
With oVars
.Add("WMargTop").Value = WMargTop
.Add("WMargBot").Value = WMargBot
.Add("WMargLft").Value = WMargLft
.Add("WMargRgt").Value = WMargRgt
End With
With oDoc.PageSetup
.TopMargin = InchesToPoints(oVars("WMargTop").Value)
.BottomMargin = InchesToPoints(oVars("WMargBot").Value)
.LeftMargin = InchesToPoints(oVars("WMargLft").Value)
.RightMargin = InchesToPoints(oVars("WMargRgt").Value)
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Dialogs(wdDialogInsertPicture)
.Name = "http://www.broesj.com/Kop4.jpg"
.FloatOverText = False
.Execute
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.TypeText Text:="here is text"
Selection.MoveLeft Unit:=wdCharacter, Count:=192, Extend:=wdExtend
Selection.Font.Name = "Verdana"
Selection.Font.Size = 6
ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
Dim asection As Section
Set asection = Selection.Sections(1)
With asection
With .PageSetup
End With
'tekst header pagina 1
ActiveWindow.ActivePane.View.SeekView = wdHeaderFooterFirstPage 'HEADER PAGINA 1
With Dialogs(wdDialogInsertPicture)
.Name = "http://www.broesj.com/Kop3.jpg"
.FloatOverText = False
.Execute
End With
'footer lettertype enzo
.Footers(wdHeaderFooterFirstPage).Range.Text = "here is text"
ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage).Range.Select
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Name = "Verdana"
Selection.Font.Size = 6
ActiveWindow.ActivePane.View.Type = wdPageView
End With
End Sub