Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-24-2021, 08:00 AM
handclips handclips is offline Attaching all PDFs in folder to Outlook email Windows 10 Attaching all PDFs in folder to Outlook email Office 2019
Novice
Attaching all PDFs in folder to Outlook email
 
Join Date: Jun 2020
Posts: 4
handclips is on a distinguished road
Default Attaching all PDFs in folder to Outlook email


Hi

I want to attach all PDFs in a specific desktop folder to an Outlook email using VBA in Word

I'm using below code to generate an Outlook email but cant figure out how to write the attachment part.

Sub Email_Template1()

Dim oMailItem As Object, oOLapp As Object
Dim Word As Object, doc As Object, MsgTxt$
Set oOLapp = CreateObject("Outlook.Application")
Set oMailItem = oOLapp.CreateItem(0)
Set Word = CreateObject("word.application")

With oMailItem
.To = "Email"
.cc = "Email"
.subject = "Needed Confirmation"
' .attachment.Add
.HTMLBody = "test"
.Display
End With

Set oOLapp = Nothing
Set oMailItem = Nothing

End Sub
Reply With Quote
  #2  
Old 01-25-2021, 06:05 AM
gmayor's Avatar
gmayor gmayor is offline Attaching all PDFs in folder to Outlook email Windows 10 Attaching all PDFs in folder to Outlook email Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

Cross posted at Reload this Page Attaching all PDFs in folder to Outlook email using Word VBA
and Attaching all PDFs in folder to Outlook email using Word VBA - Excel VBA / Macros - OzGrid Free Excel/VBA Help Forum

That's fairly straightforward e.g.

Code:
Dim oMailItem As Object, oOLApp As Object
Dim Word As Object, doc As Object, MsgTxt$
Dim strFile As String
Const strPath As String = "C:\Path\"
    Set oOLApp = CreateObject("Outlook.Application")
    Set oMailItem = oOLApp.CreateItem(0)
    'Set Word = CreateObject("word.application") '?

    With oMailItem
        .To = "Email"
        .CC = "Email"
        .Subject = "Needed Confirmation"
        strFile = Dir$(strPath & "*.pdf")
        While strFile <> ""
            .Attachments.Add strPath & strFile
            strFile = Dir$()
        Wend
        .HTMLBody = "test"
        .Display
    End With

    Set oOLApp = Nothing
    Set oMailItem = Nothing
__________________
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
  #3  
Old 01-25-2021, 01:27 PM
macropod's Avatar
macropod macropod is offline Attaching all PDFs in folder to Outlook email Windows 10 Attaching all PDFs in folder to Outlook email Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Handclips: This is the second time you've been caught cross-posting without providing links. Third strike and you're out.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Attaching all PDFs in folder to Outlook email Merge 3 PDFs in each folder in a sigle PDF eduzs Word VBA 3 09-02-2018 04:26 AM
help with deleting email folder in Outlook marty364 Outlook 0 01-09-2016 11:15 PM
Attaching a folder alamorchgirl Misc 0 06-16-2011 06:32 PM
Attaching all PDFs in folder to Outlook email Outlook 2010 email folder question. salin Outlook 4 04-25-2011 10:29 AM
Attaching all PDFs in folder to Outlook email folder missing from outlook 7 email tree blueskyflowers Outlook 1 10-06-2010 01:37 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:17 AM.


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