PDA

View Full Version : Outlook attachment help



oneillp111
07-19-2013, 07:30 AM
Hey Guys,

Hopefully this is a simple solution but i cant seem to figure it out. I have created a simple macro that I attached to a button on the QAT. The macro opens a template with the required addresses and it works fine. What I would like to add to the macro is that when it is executed, I would like the add attachment window to open automatically and if possible open to a specific location. Not a big problem but just trying to make this process faster.

This is my macro. Ideally I would like to have this macro in a word document and attach the active document to the outlook template.


Sub CreateFromTemplate()
Set MyItem = Application.CreateItemFromTemplate("C:\Users\oneilp6\Documents\test.oft")
MyItem.Display
End Sub

skatonni
07-25-2013, 09:39 AM
Hey Guys,

... Ideally I would like to have this macro in a word document and attach the active document to the outlook template.


Sub CreateFromTemplate()
Set MyItem = Application.CreateItemFromTemplate("C:\Users\oneilp6\Documents\test.oft")
MyItem.Display
End Sub

Try this code in Word


Sub SendDocumentAsAttachment()

' http://answers.microsoft.com/en-us/office/forum/office_2010-word/i-need-to-email-the-word-document-as-an-attachment/4bdc5b0b-0286-43e1-8abd-7adb7cfc6f6d?

' http://www.word.mvps.org/FAQs/InterDev/SendMail.htm

' Sends the document as attachment using Outlook
' provided the document has been saved at least once

' Make a reference to Microsoft Outlook Object Library

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)
Set oItem = oOutlookApp.CreateItemFromTemplate("C:\Users\oneilp6\Documents\test.oft")
With oItem

'.To = "recipient@nodonotmail_untiltested"

'.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
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:="Document as attachment"
.Display

' or

'.Send

End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub