Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-20-2023, 04:58 PM
MDom MDom is offline Macro to bold and center the first line of each page. Windows 10 Macro to bold and center the first line of each page. Office 2013
Novice
Macro to bold and center the first line of each page.
 
Join Date: Apr 2022
Posts: 4
MDom is on a distinguished road
Default Macro to bold and center the first line of each page.

Hi all,



Totally new to VBA but trying my best...I've searched for the answers but evidently dealing with pages is more challenging than I think it should be.

I have the following macro that bolds and centers the first line of the document, then goes through the first four pages of a document and selects and bolds the first line (which for me, is always a title). Then it goes back to the first page. So far it works great.

I believe a loop would be more efficient (especially since not every document is always four pages), but I'm failing miserably even getting started in building the loop. Can anyone help me turn what I have into a macro that loops through the document and bolds and centers the first line of each page? Thank you in advance!

Sub FirstLineCenter()
'
Dim ParaRange As range
Dim StartRange As range

Set StartRange = Selection.range

Set ParaRange = ActiveDocument.Paragraphs(1).range
ParaRange.Select
Selection.Font.Bold = True
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=1
Set ParaRange = ActiveDocument.Bookmarks("\Page").range.Paragraphs (1).range
ParaRange.Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Bold = True

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=1
Set ParaRange = ActiveDocument.Bookmarks("\Page").range.Paragraphs (1).range
ParaRange.Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Bold = True

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=1
Set ParaRange = ActiveDocument.Bookmarks("\Page").range.Paragraphs (1).range
ParaRange.Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Bold = True

Selection.HomeKey Unit:=wdStory

End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to make a LINE BOLD under cursor Retko Word VBA 4 01-28-2022 03:38 AM
Macro to bold and center the first line of each page. Justify left center and right center on same line DiGug Word 3 10-02-2014 02:43 PM
Format Bold in one line makes all lines bold Nitte Word 2 02-07-2013 12:34 AM
How to Center One Line Vertically on Blank Page SQLUSA Word 1 08-29-2012 08:14 PM
Macro that will go to line # and center text marge Word VBA 0 09-10-2010 12:30 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:29 PM.


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