+ Reply to Thread
Results 1 to 2 of 2

Listbox to ask for files to attach

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Canada
    MS-Off Ver
    OFFICE 365
    Posts
    183

    Listbox to ask for files to attach

    I have this code for listbox, how can modify the code to ask for files to attach before opens outlook?

    Code:

    Option Explicit
    'Populate a multi-column combo and list box with values from spreadsheet
    'when the form is loaded
    Private Sub UserForm_activate()
    Dim MyList(47, 5) 'as array type
    Dim R As Integer

    'The list box contains 3 data columns.
    'You can configure the number of columns, their width and height below
    'as well as change the text in the ControlTipText of the listbox
    Application.ShowToolTips = True
    With ListBox1
    .ColumnCount = 5
    .ColumnWidths = 80
    '.Width = 230
    '.Height = 110
    .ControlTipText = "Click the Name, Job, or ID you're after"
    End With
    'Define the list and where it's obtained from (Columns A, D, G in this example)
    With ActiveSheet
    'MyList (Row{0 to 9}, Column{0 to 2}) = the ranges given
    For R = 0 To 47
    MyList(R, 0) = .Range("A" & R + 1)
    MyList(R, 1) = .Range("b" & R + 1)
    MyList(R, 2) = .Range("c" & R + 1)
    MyList(R, 3) = .Range("d" & R + 1)
    MyList(R, 4) = .Range("e" & R + 1)
    Next R
    End With
    'populate the list box
    ListBox1.List = MyList
    End Sub
    'When a name in the listbox is clicked, select the corresponding row
    Private Sub listBox1_Click()
    Dim Employee As Variant
    Dim Name As String
    Dim firstaddress As String

    Employee = Empty
    'If you add more than 500 names you will need to increase this
    With ActiveSheet.Range("a2:e500")
    Name = ListBox1.Value
    Set Employee = .Find(what:=Name, LookIn:=xlValues)
    If Not Employee Is Nothing Then Employee.Rows.EntireRow.Select Else Exit Sub
    End With
    'closes the form when you click on a name
    ' Unload Me
    Dim ce As Range, i As Long
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strto As String, strcc As String, strbcc As String
    Dim strsub As String, strbody As String
    Dim wksht As Worksheet
    Dim rw As Integer

    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)

    Set wksht = Worksheets("Data")
    rw = ActiveCell.Row

    strto = wksht.Cells(rw, "b").Value
    strcc = "" '.Cells(i, 4).Value
    strbcc = ""
    strsub = "Transaction ID: " & wksht.Cells(rw, "e").Value
    strbody = "Hi" & _
    vbCrLf & vbCrLf & "Thank you."
    'End With

    With OutMail
    .To = strto
    .CC = strcc
    .BCC = strbcc
    .Subject = strsub
    .Body = strbody
    '.Send
    .display

    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
    Set Employee = Nothing

    With UserForm1
    Unload Me
    End With
    [a1].Select
    End Sub

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,054

    Re: Listbox to ask for files to attach

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Never use Merged Cells in Excel

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Is there a way for users to attach files within a worksheet?
    By ilovefood516 in forum Excel General
    Replies: 1
    Last Post: 03-21-2015, 05:50 AM
  2. Attach multiple files to an email
    By startuga in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2014, 02:18 PM
  3. [SOLVED] Unable to attach files to thread.
    By JO505 in forum Suggestions for Improvement
    Replies: 10
    Last Post: 08-16-2013, 12:35 PM
  4. Whyyyyyyy can't you attach files in a private message?
    By LaffyAffy13 in forum Suggestions for Improvement
    Replies: 8
    Last Post: 08-09-2013, 11:35 AM
  5. Application.GetOpenFilename, Attach files to Email, Move files, Delete Original.
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2009, 12:11 AM
  6. How to attach files to the forum - on a Mac
    By Jenrich in forum Excel General
    Replies: 0
    Last Post: 06-03-2009, 03:55 PM
  7. [SOLVED] I want to attach word files or PDF files to an excel database
    By Dianne Munro in forum Excel General
    Replies: 1
    Last Post: 03-22-2006, 08:15 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1