I have been using the “Outlook Automation” code with a Word document (which has form fields filled in by the user), to send the document as an attachment (see code below). I added the save command at the beginning of the code. I have a checkbox on the form, which runs the code when it is checked.
Since we switched to Office 2007, sometimes the document sends blank and sometimes it sends with the data filled in. I see the save command run so I know it saves. We have been opening the document via a link in IE.
I saved a copy to a network folder and tried executing the code and get the error: “Run-time error 446 Object doesn’t support named arguments” on the .attachments line of code.
Do I need to do something different for Office 2007? I can’t find any differences in the users that work and those that don’t.
Any Ideas? Thanks!
Patty
You can send the document as attachment using Outlook provided the document has been saved at least once:
Sub SendDocumentAsAttachment()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
ChangeFileOpenDirectory _
“filepath”
ActiveDocument.SaveAs FileName:= _
“filename”, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:=””, AddToRecentFiles:= _
True, WritePassword:=””, ReadOnlyRecommended:=True, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
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 = “recipient@mail.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
.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