Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vba sendmail as an attachment and auto populate the "to" Field

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
chet58 (Visitor) Jul 3, 2002
I want to build a template and put a button on the bottom of the template. When I (or anyone else) clicks on the button what I want to have happen is... I want the template or document that I am currently in to be automatically placed in an email as an attachment (we use outlook).
So far I found a pretty simple way to do this but here is the clincher. I want the email to be addressed to: a predetermined person or persons. So a recap. Say I want my email to go to johndoe@whatever.com and a cc to go to bobdoe@whatever.com I want the users to (just with the click of a button)have the document they are in be placed in an email that is addressed to the above people and then the user only has to do a quick review of the email with attachments before clicking the send button.
I have been trying to make this work for a few weeks off and on....please help me...
 
The only way I have been able to accomplish this is to create a new form in Outlook containing the names of the people I want to send TO: and CC: and save as a .OFT file. If you use this form on a network everyone on your network will be able to use the form. To create the form:

Using Outlook 2000:
1) Create a new email.
2) Address the email as you normally would.
3) Under Tools - Forms - Design This Form
4) File - Save as (save file to network so all can access)
5) Write your code to access this file when sending email.

Hope this helps, it works for me.

Dave
 
From VBA help file
expression.SendMail(Recipients, Subject, ReturnReceipt)

so:
mySubject = "This is my subject"
myRecipients = "ANOther@Somewhere.co.uk , SomeoneElse@Somewhereelse.co.uk"
Activeworkbook.sendmail Recipients:= myRecipients_ subject:=mySubject

watch the wordwrap on the last line
Ok - so you won't get a cc but without opening up the outlook object you're not gonna get the cc

If you want the recipients and subject to be dynamic, use something like
myRecipients = range("A1").text & " , " & range("A2").text
etc etc

HTH
Geoff HTH
~Geoff~
 
Nothing to do with this thread.
Just a message to ~Geoff~ ..... you are cool !
I can't keep up to you.
:)
Ratman
 
Nothing to do with this thread.
Just a message to ~Geoff~ ..... you are cool !
I can't keep up with you.
:)
Ratman
 
Hi, I tried what you suggested and I recieved an error (please remember I am a newbie at VBA. Here is what I did. I opened a new word doc. I placed a command button on the doc and then doubleclicked on the command button. This took me into the project explorer. I cut and pasted the code you gave me and replace the fake email addressses with real ones from two of my colleges.

Before I could leave the project explorer I recived this screen the last line of text (beggining with "Activeworkbook....") turns red and if I try to leave this screen an error message "compile error: Sytax error" comes up.

Any Ideas?

Thanks again and this is the code I currently have:

Private Sub CommandButton1_Click()
mySubject = "This is my subject"
myRecipients = "ddd@krammerltd.com, bbb@krammerltd.com"
Activeworkbook.sendmail Recipients:= myRecipients_ subject:=mySubject

End Sub

 
Yes indeed - I (stupidly) thought you were working in excel (hence the workbook). I'm not too hot on word vba but I think the syntax is
Activedocument.sendmail

Try typing in send or sendmail in the VBA help in word - should give you some more info

HTH
~Geoff~
[noevil]
 
This works:

Set OutlookItem = Outlook.CreateItem(0)
With OutlookItem
.To = EmailAddress
.Subject = "FDA Data - FDINFO.DAT from " & EDIID
.Attachments.Add OutputFilePathJW + OutputFileName
.Body = "your text here..."
.Save
.Send
End With

.cc might work too, not tried
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top