0

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?

James
  • 1,928
  • 3
  • 13
  • 30

1 Answers1

2

You might try:

cc.Range.Text = Replace(CreditNotes.Text, vbCrLf, vbNullString)
K Paul
  • 134
  • 10