Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-25-2023, 05:00 AM
gmaxey gmaxey is offline Header with Page Number through VBA Windows 10 Header with Page Number through VBA Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

In your document template, create a building block entry of the Primary Page Header content (minus the final paragraph mark). Name it "HPP"




Create a building block entry of the Even Page Header content (minus the final paragraph mark). Name it "HEP"


Run this macro:

Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oHF As HeaderFooter
Dim oRng As Range
  For Each oHF In ActiveDocument.Sections(1).Headers
    Set oRng = oHF.Range
    Select Case oHF.Index
      Case wdHeaderFooterPrimary
        oRng.Text = vbNullString
        oRng.Collapse wdCollapseStart
        ActiveDocument.AttachedTemplate.BuildingBlockEntries("HPP").Insert oRng
      Case wdHeaderFooterEvenPages
        oRng.Text = vbNullString
        oRng.Collapse wdCollapseStart
        ActiveDocument.AttachedTemplate.BuildingBlockEntries("HEP").Insert oRng
     End Select
  Next
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
header numbers, header page numbering, header template



Similar Threads
Thread Thread Starter Forum Replies Last Post
Header with Page Number through VBA Problem with page number header webgal318 Word 4 06-22-2020 06:40 PM
Don't want page number or date in footer on first page, do want graphic in header. dianahbr Word 2 02-23-2018 09:25 AM
Header with Page Number through VBA Header and page number rimutaka Word 4 06-01-2016 08:30 PM
Header with Page Number through VBA Change page number in header on page x of y - y has too many pages wpryan Word VBA 3 07-17-2015 07:04 AM
Header with Page Number through VBA Header and page number atitool Word 1 11-06-2014 06:42 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft