code to attach files
Chad,
I am currently working on a program that allows the user to email the excel
document but I also need to attach supporting files with it (usually a word
document as well), however those documents change constantly so it will
easier to have the code grab the files than set up the code each time for
each document. I have created a folder where all the supporting documents
reside. Would you be willing to share the code, that allows you to loop
through the folder and attaches all the files, just like the "Select All" you
posted in the message. I saw the code for the DIR from the help excel
website but I was not able to modify it successfully to allow for it attach
all files, it looped correctly, when I ran the example as is. However my
modified code give me automation errors, when it ran. Any ideas or pointers
in the right direction will help. I am learning visual basic so I do
understand the concepts. Any help will be most appreciated.
Karen
"Chad" wrote:
here's a portion of the code i use:
'You must add a reference to the Microsoft outlook Library
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
Dim strbody As String
strbody = "Email body text"
With OutMail
.To = "
'.CC = ""
'.BCC = ""
subjectline = "test email
.Subject = subjectline
.Body = strbody
.Importance = olImportanceHigh
.ReadReceiptRequested = True
'define attachment
attachmentname = "c:\" 'adjust to your directory
Set myAttachments = OutMail.Attachments
myAttachments.Add attachmentname
.Send 'or use .Display to display the message prior to sending
End With
hope this helps,
-chad
"Stefi" wrote:
Hi Chad,
Could you share with me the code or the concept of sending an e-mail WITH
SPECIFIC FILES ATTACHED through VBA?
Thanks in advance!
Stefi
€˛Chad€¯ ezt Ć*rta:
I have code that generates an email and attaches specific files. I would
like to know if there is VBA code to be able to attach ALL files within a
specific folder, not just one specific file. Kind of like a "select all"
within a folder that attaches all selected items to an email. Any thoughts?
Thanks in advance.
-Chad
|