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

Auto Email Macro in Word 1

Status
Not open for further replies.

ChefSausage

Programmer
Oct 19, 2002
36
US
In Word I'm trying to create a hyperlink that pops up an email window with the document attached. I have the basic function down with these lines:

Options.SendMailAttach = True
ActiveDocument.SendMail

All I need now is to have a recipient email address that goes with it. It's always the same address so it can be hardcoded, and I don't want the document to save before sending. This one is driving me batty.
 
Don't know about Word, but Visual Basic in Access2000 will send a file on the pc with this code:

Make appropriate changes. I use another app run in a .bat file to create the current file to send before running this one.


Private Sub Command2_Click()
Dim patha As String
Dim result As Integer
Dim displaymessage As Boolean
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
patha = "c:\abc.zip"
displaymessage = True
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("red54@iocorp.net")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("webmaster@iocorp.net")
objOutlookRecip.Type = olCC

' Add the BCC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("don@iocorp.net")
objOutlookRecip.Type = olBCC

' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
'If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(patha)
'End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

' Should we display the message before sending?
If displaymessage Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub
Time flies when you don't know what you're doing...
 
This is very much appreciated, but the problem here is I have no idea where the user will store the file, so the patha variable won't cut it.
 
Did you ever solve this problem? I am trying to do the same thing and I can't figure out how to hardcode in the recepient's address. It shouldn't be that tuff but it is driving me to drink.

Thanks.
 
Try the following

ActiveSheet.Copy
Application.Dialogs xlDialogSendMail).Show "Recipient@tester.com", "Subject Matter"
 
I am trying to something similar but in a .mht file. I tried the submit and mailto: but it doesn’t attach my web form.

By the way I was able to do it in a word form with

Private Sub CommandButton1_Click()
Options.SendMailAttach = True
ActiveDocument.SendMail
End Sub

Anyone know how to do this on a web page?
 
ChefSausage,
You might consider using the routing slip. It will let you set the recipient, subject and body text as well as other options. Example code below.
Hope this helps
Sub mailit()
ActiveDocument.HasRoutingSlip = True
ActiveDocument.RoutingSlip.AddRecipient "sdraper@ilsos.net"
ActiveDocument.RoutingSlip.Subject = "Hey this got Routed"
ActiveDocument.RoutingSlip.Message = "Here's the body text"
ActiveDocument.Route
End Sub


Sam
 
I have tried this macro script, but it gives me the error Microsoft Outlook Does Not Recongnize "Unknown".
 
I got this from this also has alternate verisons of the same type of program too.

First go to Tools>Refrences to set(check off) the Outlook refrence in the visual basic editor or this wont work:

Sub Macro1()

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(&quot;Outlook.Application&quot;)
bStarted = True
End If

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
.To = &quot;recipient@mail.com&quot;
.CC = &quot;recipient2@mail.com&quot;
'Set the subject
.Subject = &quot;New subject&quot;
'The content of the document is used as the body for the email
.Body = &quot;The hardcoded body text goes here DUDE&quot;
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:=&quot;Document as attachment&quot;
.Send
End With

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub
 
Dudeman, it sounds like Outlook doesn't recognize the email address you are giving it.

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top