VBA for ContentControl returning multiple lines of text

SuziBaz

New Member
Joined
Nov 2, 2017
Messages
13
Hi,

I'm new to VBA and am trying to create VBA for a form in which a user will choose an option (Grade 1, 2 or3) from a Content Control Dropdown list and then the text will return as variable text.
The issue I am having is that the returned text has multiple lines (about 12) which need to be on individual lines and the VBA I am using is not returning this on individual lines.
I am using & Chr(10) & and also I have tried & vbLf & and also & vbNewLine &

The VBA sample is below:

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrDetails As String, StrDesc As String
With ContentControl
If .Title = "Grade" Then
For i = 1 To .DropdownListEntries.Count
If .DropdownListEntries(i).Text = .Range.Text Then
StrDetails = .DropdownListEntries(i).Value
If StrDetails = "Grade 1" Then
StrDesc = "All new employees with less than two years employment will be entitled to Statutory Sick Pay." & vbLf & "After two years employment the Company will supplement the statutory sick pay of qualifying employees to an amount equivalent to the full basic wage level to the periods indicated below."
ElseIf StrDetails = "Grade 2" Then
StrDesc = "Text to be added here"
ElseIf StrDetails = "Grade 3" Then
StrDesc = "Text to be added here"
End If
Exit For
End If
Next
With ActiveDocument
With .SelectContentControlsByTitle("txtGrade")(1).Range
If StrDesc <> "" Then
.Text = StrDesc
End If
End With
End With
End If
End With


End Sub


Can anyone please advise?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
vbLf or vbCrLf works if txtGrade is a rich text control, not a plain text control.

Thank you John_w,

This has enlightened me, I have entered the Content Control Properties and ticked the box for Plain Text Properties to "Allow Carriage Returns"
 
Upvote 0

Forum statistics

Threads
1,223,767
Messages
6,174,395
Members
452,561
Latest member
amir5104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top