Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-13-2018, 04:16 AM
SuziBaz SuziBaz is offline VBA for ContentControl returning multiple lines of text Windows 10 VBA for ContentControl returning multiple lines of text Office 2016
Novice
VBA for ContentControl returning multiple lines of text
 
Join Date: Apr 2018
Posts: 3
SuziBaz is on a distinguished road
Default VBA for ContentControl returning multiple lines of text

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:

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

Last edited by SuziBaz; 04-13-2018 at 06:18 AM. Reason: Added code tags
Reply With Quote
  #2  
Old 04-13-2018, 04:31 AM
eduzs eduzs is offline VBA for ContentControl returning multiple lines of text Windows 10 VBA for ContentControl returning multiple lines of text Office 2010 32bit
Expert
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default

Try chr(13)? Multiline content control is a bit tricky, hope someone else can help.
Reply With Quote
  #3  
Old 04-13-2018, 05:14 AM
SuziBaz SuziBaz is offline VBA for ContentControl returning multiple lines of text Windows 10 VBA for ContentControl returning multiple lines of text Office 2016
Novice
VBA for ContentControl returning multiple lines of text
 
Join Date: Apr 2018
Posts: 3
SuziBaz is on a distinguished road
Default

Unfortunately this doesn't work either

Let's hope there's someone out there that is a Whizz on multiline content control
Reply With Quote
  #4  
Old 04-13-2018, 06:13 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline VBA for ContentControl returning multiple lines of text Windows 7 64bit VBA for ContentControl returning multiple lines of text Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,766
Pecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant future
Default

@Suzi
Hello and welcome
in the future could you please wrap your code with code tags ? ( click Go advanced - select code and click the #button)
Thank you
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post
Reply With Quote
  #5  
Old 04-13-2018, 06:18 AM
SuziBaz SuziBaz is offline VBA for ContentControl returning multiple lines of text Windows 10 VBA for ContentControl returning multiple lines of text Office 2016
Novice
VBA for ContentControl returning multiple lines of text
 
Join Date: Apr 2018
Posts: 3
SuziBaz is on a distinguished road
Default

Thank you Pecoflyer...Duly Noted
Reply With Quote
  #6  
Old 04-13-2018, 05:11 PM
macropod's Avatar
macropod macropod is offline VBA for ContentControl returning multiple lines of text Windows 7 64bit VBA for ContentControl returning multiple lines of text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted (and answered) at: https://www.mrexcel.com/forum/genera...ines-text.html
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA for ContentControl returning multiple lines of text How to insert bookmarks for content or Text of ContentControl lvganesh Word VBA 5 12-12-2017 11:27 PM
Returning value based on multiple crtiteria stockers Excel 3 03-06-2017 05:05 PM
VBA for ContentControl returning multiple lines of text Extracting data from a cell with multiple lines of text MMT Excel 9 02-12-2015 09:18 PM
VBA for ContentControl returning multiple lines of text Multiple lines of placeholder text hanilucida PowerPoint 1 06-21-2014 05:40 AM
Macro to Insert Text Into Cells Having Multiple Lines revans611 Excel Programming 4 10-24-2011 10:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft