Scott Holtzman
Scott Holtzman

Reputation: 27249

Word VBA: Remove Paragraph Marker

I have code that automatically detects certain text based on a selection and places onto a user form.

The issue I face is removing the trailing paragraph marker. (see picture below):

enter image description here

I have tried the following and other variations, but I can't remove the trailing paragraph marker:

Dim theText As String
theText = Replace(Selection, "^p", "") 

Lastly, I know I can use Left(Selection,Len(Selection)-1), but this will fail if the paragraph marker is not there.

Upvotes: 1

Views: 1581

Answers (2)

Vityata
Vityata

Reputation: 43585

To get the paragraph in Word, use one of the following 2 options (the first works for the OP):

  • theText = Replace(Selection, ChrW$(13), "")

  • theText = Replace(Selection, ChrW$(244), "")

Upvotes: 1

Scott Holtzman
Scott Holtzman

Reputation: 27249

As provided in the comments above this is the solution:

Dim theText As String
theText = Replace(Selection, Chr(13), "")

Upvotes: 0

Related Questions