Results 1 to 7 of 7

Thread: Userform Combobox in Word

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    Well lets just clean the whole mess up while we are at it:

    In the form module use:

    Option Explicit
    
    Private Sub UserForm_Initialize()
      With Circumstances
        .AddItem "we reviewed your plan"
        .AddItem "we discussed a tax strategy"
        .AddItem "you mentioned"
        .AddItem "recently purchased a home for $"
        .AddItem "You mentioned concerns about meetinh your financial obligations if you were not longer able to work"
        .AddItem "are expecting a new addition to your family"
        .AddItem "you are the sole income earner"
        .AddItem "you have been requested by your lender to obtain life insurance to cover your business loan"
        .AddItem "you had converns about your business continuing to operate should you become unable to work"
        .AddItem "we review your plan, which identified a need"
      End With
      'Continue as above to fill other comboboxes.
    lbl_Exit:
      Exit Sub
    
    End Sub
    
    Private Sub Commandbutton1_Click()
      Tag = "CREATE DOC"
      Hide
    lbl_Exit:
      Exit Sub
    End Sub
    
    Private Sub cmdCanx_Click()
      Hide
    lbl_Exit:
      Exit Sub
    End Sub
    
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
      If CloseMode = 0 Then
        Cancel = True
        cmdCanx_Click
      End If
    lbl_Exit:
      Exit Sub
    End Sub
    In a new standard module use:

    Option Explicit
    Dim oFrm As Why 'Strange name and caption for a form.
    Sub AutoNew()
      Set oFrm = New Why
      With oFrm
        .Show
        If .Tag = "CREATE DOC" Then
          FillDoc
        Else
          ActiveDocument.Close wdDoNotSaveChanges
        End If
      End With
    lbl_Exit:
      Exit Sub
    End Sub
    
    Sub FillDoc()
    Dim oCtrl As Object
      For Each oCtrl In oFrm.Controls
        Select Case TypeName(oCtrl)
          Case "TextBox"
            ActiveDocument.SelectContentControlsByTitle(oCtrl.Name).Item(1).Range.Text = oCtrl.Text
          Case "ComboBox"
            ActiveDocument.SelectContentControlsByTitle(oCtrl.Name).Item(1).Range.Text = oCtrl.Value
          Case "OptionButton"
            If oCtrl.Name = "Advisory" And oCtrl = True Then
              ActiveDocument.SelectContentControlsByTitle("Delivery").Item(1).Range.Text = "inform you when to expect your policy in the mail"
            ElseIf oCtrl.Name = "Mail" And oCtrl = True Then
              ActiveDocument.SelectContentControlsByTitle("Delivery").Item(1).Range.Text = "arrange for its delivery"
            End If
        End Select
      Next
    lbl_Exit:
      Exit Sub
    End Sub
    
    'Left over code.
    Sub CleanUpBookmarkMess()
      Dim oBM As Bookmark
      Dim oCC As ContentControl
      For Each oBM In ActiveDocument.Bookmarks
        Set oCC = ActiveDocument.ContentControls.Add(wdContentControlText, oBM.Range)
        oCC.Title = oBM.Name
        oCC.SetPlaceholderText , , oBM.Name
        oBM.Delete
      Next
    lbl_Exit:
      Exit Sub
    End Sub
    Rename your option buttons "Advisory" and "Mail"

    One of those attachments has a Stop in the code, but I couldn't figure out how to delete the attachment.
    Attached Files Attached Files
    Greg

    Visit my website: http://gregmaxey.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •