Share via

VBA Code for Centering a Line

Anonymous
2012-12-14T22:31:15+00:00

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?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2012-12-15T00:01:42+00:00

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() <br><br><br>ActiveDocument.Paragraphs(1).Alignment = wdAlignParagraphRight <br><br><br>End Sub

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful