Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Aug 2002
    Location
    Wichita, Kansas, USA
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  2. #2
    Star Lounger
    Join Date
    Aug 2002
    Location
    Wichita, Kansas, USA
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Update - I tried saving it to a network folder and running the code again and it worked correctly.

    I noticed before and forgot to mention:
    When I send the form via the email code and it comes in blank
    then I look at the file in the directory indicated in the code
    the file contains the data from the last correct save and not from the save I just saw run with the code in the document

    So maybe it is a problem with the save command - but I don't get an error on the save.

    Patty

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Is the switch to Office 2007 the only change, or did your users also move to another Windows version, e.g. from Windows XP to Windows Vista?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •