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?
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?