Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-22-2023, 07:15 AM
Rajesh1297 Rajesh1297 is offline Header with Page Number through VBA Windows 11 Header with Page Number through VBA Office 2019
Novice
Header with Page Number through VBA
 
Join Date: Jul 2023
Posts: 2
Rajesh1297 is on a distinguished road
Default Header with Page Number through VBA

Hi Every one,



we are looking solution here for the header placement with page number through VBA. Can anyone help us to resolve this issue?

left Side Page we want a title with the Page number
right side Page we want Author's name with the Page number

attaching a Word file for your ref.
Attached Files
File Type: docx Test File.docx (16.6 KB, 9 views)
Reply With Quote
  #2  
Old 07-24-2023, 07:59 AM
Italophile Italophile is offline Header with Page Number through VBA Windows 11 Header with Page Number through VBA Office 2021
Expert
 
Join Date: Mar 2022
Posts: 539
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Why do you need VBA for this?

Just use the Title and Author content controls that you find under Insert | Quick Parts | Document Property on both the front page and in the header.
Reply With Quote
  #3  
Old 07-24-2023, 11:30 PM
Rajesh1297 Rajesh1297 is offline Header with Page Number through VBA Windows 11 Header with Page Number through VBA Office 2019
Novice
Header with Page Number through VBA
 
Join Date: Jul 2023
Posts: 2
Rajesh1297 is on a distinguished road
Default

Thank you for your suggestion.

we have tried to use Quick Part as well. but in every file we do the manual setting and its taking time to add every time. we have 1000+plus file and we want minimum manual work to be added header.
Reply With Quote
  #4  
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,600
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 07:56 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