Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Thread Tools Display Modes
Old 07-08-2019, 03:42 PM
hotdogsnmustard hotdogsnmustard is offline Automating attachment email Windows 10 Automating attachment email Office 2016
Automating attachment email
Join Date: Jul 2019
Posts: 1
hotdogsnmustard is on a distinguished road
Default Automating attachment email


i'm after a way to automate an attachment email.

i regularly download a file from the internet. the name of the file includes the date and time, so each time it is slightly different, but it will always include the words "FremanWebThermalLabel"
i currently right click in my downloads and then send to mail recipient. and i am always sending it to the same email address.

is it possible to create a code or something so that when i right click it and select mail recipient it recognises that the file name has this phrase and automatically selects the right recipient and then sends it automatically.

thanks in advance.
Reply With Quote
Old 07-08-2019, 08:30 PM
gmayor's Avatar
gmayor gmayor is offline Automating attachment email Windows 10 Automating attachment email Office 2016
Join Date: Aug 2014
Posts: 3,313
gmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to all

The short answer is no, and it would be better if you ran the process from Excel or Word as Outlook doesn't have the filedialog selector, but it can be done from Outlook VBA e.g. as follows. Run the macro and select the file to attach.

Option Explicit

Sub Send_As_Attachment()
'Graham Mayor - - Last updated - 09 Jul 2019
Dim olItem As MailItem
Dim olInsp As Inspector
Dim wdDoc As Object
Dim oRng As Object
    'Change the values below as appropriate
Const strSubject As String = "This is the message subject"
Const strRecipient As String = ""
Const strMessage As String = "This is the message body text" & vbCr & vbCr & _
      "This is another paragraph of message body"

    Set olItem = CreateItem(0)
    With olItem
        .BodyFormat = 2
        .To = strRecipient
        .Subject = strSubject
        .Attachments.Add BrowseForFile
        Set olInsp = olItem.GetInspector
        Set wdDoc = olInsp.WordEditor
        Set oRng = wdDoc.Range
        oRng.collapse 1
        oRng.Text = strMessage
    End With
    Set olItem = Nothing
    Set olInsp = Nothing
    Set wdDoc = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub

Function BrowseForFile(Optional sName As String) As String
Dim exApp As Object
Dim strPath As String: strPath = ""
Dim fDialog As FileDialog
Dim bStarted As Boolean
    On Error Resume Next
    Set exApp = GetObject(, "Excel.Application")
    On Error GoTo 0
    If exApp Is Nothing Then
        Set exApp = CreateObject("Excel.Application")
        bStarted = True
    End If

    Set fDialog = exApp.FileDialog(msoFileDialogFilePicker)
    With fDialog
        .Title = "Select attachment"
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then GoTo err_Handler:
        BrowseForFile = fDialog.SelectedItems.Item(1)
    End With
    If bStarted = True Then exApp.Quit    'Optional
    Set exApp = Nothing
    Exit Function
    BrowseForFile = vbNullString
    Resume lbl_Exit
End Function
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes
Reply With Quote

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automating pdf attachment process avg_acct Outlook 1 07-03-2017 08:07 PM
Email sends mailmerge file behind email rather than attachment TLC1974 Mail Merge 2 07-22-2016 12:53 AM
Automating attachment email How to add attachment to email merge Claytocb Mail Merge 5 09-12-2012 06:02 PM
Printing a sent email with attachment Karen Rose Outlook 0 05-20-2011 03:28 AM
Automating attachment email email as pdf attachment - subject line and attachment named after mail merge Nexus Mail Merge 12 04-13-2011 11:34 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 10:45 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd. is not affiliated with Microsoft