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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Sending emails

Status
Not open for further replies.

mike718

Programmer
Jul 7, 2004
58
US
I do not know if this is posible using VBA, but I have a document in word that I would like to send to the same recipients every month, how can I send it. I would be sending it utilizing outlook. Thanks
 
Actually I figured out how to send the emails. Another issue that I have come across is the security settings. Everytime you send an email from a word document through outlook you get a message "A program is trying to automatically send e-mail on your behalf. Do you want to allow this?" I understand that this is probably a security setting to prevent macros from being sent but is there a way for me to invoke some sort of signature to say yes this is OK from this user. Thanks.

My code now is:

Public Sub SendDocument()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next

If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If

Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
.To = "mike_718@someplace.com"
.Subject = "New subject"
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
.Body = ActiveDocument.Content
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:="Document as attachment"
.Send
End With

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub
 
Actually I figured out that part of it to. Thanks for reading though
 
There are 2 FAQs dealing with this

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top