View Single Post
 
Old 02-26-2015, 07:36 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
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

From what I can see of your code, you have umpteen macros that add to the document. If I am correct in that you want to select these from a userform, then create add a list box and two buttons to your userform1. Call the buttons btnOK and btnCancel. Leave the ListBox as Listbox1

Add the following code to the module with the attachments code:

Code:
Sub Add_Attachments()
Dim oHeader As HeaderFooter
Dim oRng As Range
Dim oFld As Range
Dim i As Long
Dim oFrm As New UserForm1
    With oFrm
        For i = 1 To 9
            .ListBox1.AddItem "Attachment " & i
        Next i
        .ListBox1.ListIndex = -1
        .Show
        If .Tag = 0 Then GoTo lbl_Exit
        For i = 0 To .ListBox1.ListCount - 1
            If .ListBox1.Selected(i) Then
                Set oRng = ActiveDocument.Range
                oRng.Collapse 0
                oRng.Select
                Select Case i
                    Case 0: Call Add_Att1
                    Case 1: Call Add_Att2
                    Case 2: Call Add_Att3
                    Case 3: Call Add_Att4
                    Case 4: Call Add_Att5
                    Case 5: Call Add_Att6
                    Case 6: Call Add_Att7
                    Case 7: Call Add_Att8
                    Case 8: Call Add_Att9
                End Select
            End If
        Next i
    End With
lbl_Exit:
    Exit Sub
End Sub
and add the following code to the userform
Code:
Private Sub btnCancel_Click()
    Me.Hide
    Me.Tag = 0
lbl_Exit:
Exit Sub
End Sub

Private Sub btnOK_Click()
Dim bSelected As Boolean
Dim i As Long
    With Me
        For i = 0 To .ListBox1.ListCount - 1
            If .ListBox1.Selected(i) Then
                bSelected = True
                Exit For
            End If
        Next i
        If Not bSelected Then
            MsgBox "Select at least one item from the list"
            .ListBox1.SetFocus
            GoTo lbl_Exit
        End If
        .Hide
        .Tag = 1
    End With
lbl_Exit:
    Exit Sub
End Sub
Note I have not made any attempt to debug your macros. This process merely calls them as your original request.
Save the document as a macro enabled template and create new documents from it.
__________________
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