user19206289
user19206289

Reputation: 1

VBA text formatting centre alignment

I'm new to VBA so apologies for ignorance!

Trying to insert some text from a form [me.CustomerName] into a location in a document [ActiveDocument.Bookmarks("bmCustName1")]. it works, but resets the text alignment to left when the original text it's replacing is centre aligned

Incorrect Code that's failing:

ActiveDocument.Bookmarks("bmCustName1").Range.ParagraphFormat.Alignment = wdAlignParagraphCenter.Text = Me.CustomerName

anyone able to tell me what the right modifier and syntax might be?

Upvotes: 0

Views: 497

Answers (1)

Timothy Rylatt
Timothy Rylatt

Reputation: 7850

The correct syntax for the code in your question is:

With ActiveDocument.Bookmarks("bmCustName1").Range
    .ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Text = Me.CustomerName
End With

Whether this will solve your issue will depend on whether the bookmark includes the end of paragraph mark.

Upvotes: 2

Related Questions