Consulting

Results 1 to 5 of 5

Thread: Macro that loads a custom form and creates the subject from select body text

  1. #1
    VBAX Newbie
    Joined
    Sep 2016
    Posts
    3
    Location

    Macro that loads a custom form and creates the subject from select body text

    Hi,
    Title; Macro that loads custom form, creates subject line from input and adds to body.
    I'm using outlook 2010.

    I'm trying to setup a macro that when you run it, it loads a dialog box which acts you for some text to input, then it takes that text and places it in the subject line and also places it in the body of the e-mail.

    Any help would be greatly appreciated as i'm new to VBA with outlook.

    Regards,

    Blake
    Last edited by blakem; 09-06-2016 at 09:18 PM. Reason: title

  2. #2
    What you ask is fairly straightforward, but you will need to post your custom form template and indicate where you want the data from the userform to be placed in the body of the form.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Sep 2016
    Posts
    3
    Location
    Thanks for the response.
    I am looking to have an invoice number put into the subject line and have that also placed in the body indicated by the brackets.
    invoicetemplate.jpg

  4. #4
    As this appears to relate to an invoice, what format is the invoice in? It might be possible to simply read the name and number from the invoice and attach the invoice to the message.
    If that is possible then that would make more sense than prompting for the name and number. However you can use input boxes (as below) or a userfrorm http://www.gmayor.com/Userform.htm to prompt for the data:
    Sub InvoiceMessage()
    Dim olEmail As Outlook.MailItem
    Dim olInsp As Outlook.Inspector
    Dim wdDoc As Object
    Dim oRng As Object
    Dim strName As String
    Dim strInvoice As String
    Dim strText As String
        strName = InputBox("Enter Name:")
        strInvoice = InputBox("Invoice Number:")
        strText = "Dear " & strName & vbCr & vbCr & _
                  "Please find attached invoice number " & _
                  strInvoice & Chr(46) & vbCr
        On Error Resume Next
        Set olEmail = CreateItem(olMailItem)
        With olEmail
            .BodyFormat = olFormatHTML
            .subject = "Invoice Number " & strInvoice
            Set olInsp = .GetInspector
            Set wdDoc = olInsp.WordEditor
            Set oRng = wdDoc.Range(0, 0)
            oRng.Text = strText
            oRng.collapse 0
            .Display
        End With
    lbl_Exit:
        Set olEmail = Nothing
        Set olInsp = Nothing
        Set wdDoc = Nothing
        Set oRng = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Newbie
    Joined
    Sep 2016
    Posts
    3
    Location
    Thanks so much for your help! It works perfectly. (Sorry for the late reply I've been out of the office)

Posting Permissions

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