PDA

View Full Version : [SOLVED:] Split ComboBox content to two DocVariables



DavG63
03-13-2017, 01:49 AM
Hi

This is probably really simple but the solution has thus far eluded me.

I have a single ComboBox with a list of names for signatories.

I'm trying to find the right code that when "David Smith" is selected "David" is assigned to one DocVariable and "Smith" to another. As I said it's probably really simple.

Any help would be gratefully received.

Thanks very much.

David

mana
03-13-2017, 05:14 AM
Split function


Sub test()
Dim s

s = Split(ActiveDocument.ContentControls(1).Range.Text)

If UBound(s) > 0 Then
MsgBox s(0) & " and " & s(1)
Else
MsgBox s(0)
End If

End Sub

gmaxey
03-13-2017, 10:44 AM
What kind of combobox? Mana is showing you the VBA split method:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim strText As String
strText = "David Smith" 'or the value of your combobox.
On Error Resume Next
'Get the first substring.
MsgBox Split(strText)(0) 'Returns a zero-based, one-dimensional array. A space is the default delimiter.
'Get the second substring
MsgBox Split(strText)(1)
lbl_Exit:
Exit Sub
End Sub