James
James

Reputation: 1982

VBA Blank Line In TextBox Causes Error

When having someone enter an input in a TextBox in VBA in Word 2016 64bit if they enter a blank line at the end of the textbox the program crashes and throws this error out. I can not figure out how to fix this and do not know what to try.

enter image description here

TextBox:

enter image description here

Code:

Set ccs = ActiveDocument.SelectContentControlsByTag("CreditNotes")
Set cc = ccs(1)
cc.Range.Text = CreditNotes.Text'

I then get the 5844 error but only if there is a blank line at the end of the textbox. Otherwise it works.

What code should I use to automatically take out the blank line so this will not throw out an error?

Upvotes: 0

Views: 489

Answers (1)

K Paul
K Paul

Reputation: 144

You might try:

cc.Range.Text = Replace(CreditNotes.Text, vbCrLf, vbNullString)

Upvotes: 2

Related Questions