#1
|
|||
|
|||
Automating attachment email
Hello,
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. |
#2
|
||||
|
||||
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.
Code:
Option Explicit Sub Send_As_Attachment() 'Graham Mayor - https://www.gmayor.com - 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 = "someone@somewhere.com" 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 .Display Set olInsp = olItem.GetInspector Set wdDoc = olInsp.WordEditor Set oRng = wdDoc.Range oRng.collapse 1 oRng.Text = strMessage '.Send End With lbl_Exit: 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 lbl_Exit: If bStarted = True Then exApp.Quit 'Optional Set exApp = Nothing Exit Function err_Handler: 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 www.gmayor.com |
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 |
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 |
email as pdf attachment - subject line and attachment named after mail merge | Nexus | Mail Merge | 12 | 04-13-2011 11:34 PM |