VBA Code for Centering a Line

I am creating a large variable string representing several paragraphs.  The paragraphs are divided by Chr(13) & Chr(10) and start with a tab character (vbTab).

Is there a similar code or character that I could use to indicate that a paragraph is to be centered or left-justified?
Answer
Answer

No.  If you want to use VBA to set the alignment of a paragraph, you would use:

 

Selection.Paragraphs(1).Alignment = wdAlignParagraphCenter

 

From the VBA help file for Alignment

 

Paragraph.Alignment Property (Word)


 

Returns or sets a WdParagraphAlignment constant that represents the alignment for the specified paragraphs. Read/write.

Syntax

expression.Alignment

expression Required. A variable that represents a Paragraph object.

Remarks

Some of the WdParagraphAlignment constants, depending on the language support (U.S. English, for example) that you've selected or installed.

Example

This example right-aligns the first paragraph in the active document.

VBA

Sub AlignParagraph()

ActiveDocument.Paragraphs(1).Alignment = wdAlignParagraphRight

End Sub


Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 85 Applies to: