drichird
07-28-2008, 03:33 PM
'...word 2007 VBA on XP sp2
'multipage document has a different firstpage header and standard headers
'(no even/odd) on rest of the pages. I need to add shape to header for rest
'of pages (not first page)
'this works for page 2,3,4 etc... in Word 2003. But in word 2007
'it changes first page header only (is there a bug in Word 2007 ? )
ActiveDocument.Sections(1).Headers _
(wdHeaderFooterPrimary).Shapes. _
AddPicture("C:\page234etc.bmp", False, True).Select
I also tried the more involved code below:
'go to the "first page" header
ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageHeader
'insert a picture into the shapes of the "first page" header
Selection.HeaderFooter.Shapes.AddPicture _
(FileName:="C:\first.bmp", _
LinkToFile:=False, SaveWithDocument:=True).Select
'give the "first page" header picture a name
Selection.ShapeRange.Name = "firstpage"
'goto 2nd page, the 2nd type of header for all other pages
'starts on the second page
ActiveDocument.Range.GoTo(wdGoToPage, wdGoToAbsolute, , "2").Select
'Select the header on page 2, but I think it selects page 1 instead
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
'insert 2nd picture into 2nd page header
'this does not work, picture ends up in first header
Selection.HeaderFooter.Shapes.AddPicture _
(FileName:="C:\second.bmp", _
LinkToFile:=False, SaveWithDocument:=True).Select
Selection.ShapeRange.Name = "secondpage"
'multipage document has a different firstpage header and standard headers
'(no even/odd) on rest of the pages. I need to add shape to header for rest
'of pages (not first page)
'this works for page 2,3,4 etc... in Word 2003. But in word 2007
'it changes first page header only (is there a bug in Word 2007 ? )
ActiveDocument.Sections(1).Headers _
(wdHeaderFooterPrimary).Shapes. _
AddPicture("C:\page234etc.bmp", False, True).Select
I also tried the more involved code below:
'go to the "first page" header
ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageHeader
'insert a picture into the shapes of the "first page" header
Selection.HeaderFooter.Shapes.AddPicture _
(FileName:="C:\first.bmp", _
LinkToFile:=False, SaveWithDocument:=True).Select
'give the "first page" header picture a name
Selection.ShapeRange.Name = "firstpage"
'goto 2nd page, the 2nd type of header for all other pages
'starts on the second page
ActiveDocument.Range.GoTo(wdGoToPage, wdGoToAbsolute, , "2").Select
'Select the header on page 2, but I think it selects page 1 instead
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
'insert 2nd picture into 2nd page header
'this does not work, picture ends up in first header
Selection.HeaderFooter.Shapes.AddPicture _
(FileName:="C:\second.bmp", _
LinkToFile:=False, SaveWithDocument:=True).Select
Selection.ShapeRange.Name = "secondpage"