Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 08-16-2020, 08:22 PM
gmayor's Avatar
gmayor gmayor is offline ComboBox Variable AND list Windows 10 ComboBox Variable AND list Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Personally I would leave out the spaces and add the space when you write to the document variable e.g.


Code:
Private Sub UserForm_Initialize()
Dim myPrefixes() As String
Dim strPrefix As String
Dim i As Integer
    myPrefixes = Split("[Select Item]|Mr.|Ms.|Det.|Dr.|Atty.|Rabbi|Ofc.|Sgt.|Cpl.|Maj.", "|")
    With Prefix1
        .List = myPrefixes
        On Error Resume Next 'the variable is missing from the document
        For i = 0 To .ListCount - 1
            If RTrim(ActiveDocument.Variables("Prefix")) = .List(i) Then
                .ListIndex = i
                Exit For
            End If
        Next i
    End With
End Sub

Private Sub CommandButton1_Click()
    If Prefix1.ListIndex <= 0 Then
        MsgBox "Select the prefix"
        Prefix1.SetFocus
        Exit Sub
    End If
    ActiveDocument.Variables("Prefix") = Prefix1.value & Chr(32)
    Unload Me
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Tags
vba combobox



Similar Threads
Thread Thread Starter Forum Replies Last Post
ComboBox Variable AND list Excel Combobox List VBA-User Excel Programming 4 01-07-2016 02:46 AM
Run Time Error '91': Object variable or With block variable not set using Catalogue Mailmerge Berryblue Mail Merge 1 11-13-2014 05:36 PM
ComboBox Variable AND list combobox list gets reset....please help Deepa Shrestha Word VBA 1 09-29-2013 09:30 PM
ComboBox Variable AND list Adding a long list of values to a combobox in Word 2003? ll4u76 Word VBA 1 04-13-2012 03:37 AM
ComboBox Variable AND list Populating ComboBox or Drop Down list with contents of a text field Billy_McSkintos Word VBA 1 09-13-2011 05:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:36 PM.


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