View Single Post
 
Old 05-05-2019, 08:41 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Private Sub CommandButton1_Click()
Dim bListAll As Boolean
Dim strList As String
Dim lngIndex As Long
  'Do you want to list "all" items in the listbox?
  bListAll = True
  'or do you want to list the item or items selected? Then set the variable above to False
  If bListAll Then
    For lngIndex = 0 To ListBox1.ListCount - 1
      If strList = vbNullString Then
        strList = ListBox1.List(lngIndex)
      Else
        strList = strList & vbCr & ListBox1.List(lngIndex)
      End If
    Next lngIndex
  Else
    For lngIndex = 0 To ListBox1.ListCount - 1
      If ListBox1.Selected(lngIndex) Then
        If strList = vbNullString Then
          strList = ListBox1.List(lngIndex)
        Else
          strList = strList & vbCr & ListBox1.List(lngIndex)
        End If
      End If
    Next lngIndex
  End If
  ActiveDocument.Range.Text = strList
  Hide
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote