View Single Post
 
Old 07-08-2019, 08:30 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
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 of
Default

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
Reply With Quote