Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Send word document as attachment

54 views
Skip to first unread message

Avishay Balderman

unread,
Oct 29, 2002, 6:39:22 AM10/29/02
to
Hi
I try to send word attachment using VBA.
The send method fail with error code 91.
Any ideas?
Here is the code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub SendDocumentAsAttachment(email_addr As String, team_leader_name As
String, tl_fn As String)

Dim bStarted As Boolean
Dim oOutlookApp As Object
Dim oItem As Object
Dim olMailItem As Object
Dim AttachmentPath As String


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)

AttachmentPath = ActiveDocument.Path & "\" & ActiveDocument.Name
oItem.To = email_addr
oItem.Subject = get_subject(tl_fn)
oItem.Attachments.Add (AttachmentPath)
Err.Clear
ActiveDocument.Close
'
' oItem.send fail with err 91
'
If Not oItem.send Then
MsgBox "Failed to send mail to " & team_leader_name & ". ERR= " &
Err.Description
End If

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub

Function get_subject(tl_fn As String)
get_subject = "Weekly status meeting summary - " & tl_fn & " - " &
Format(Date, "dd-MMM-yyyy")
End Function

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Herakel Endrawes

unread,
Nov 21, 2002, 5:47:01 AM11/21/02
to
Delete the line "Dim olMailItem As Object" you do not need it.

As general the On "Error Resume Next" is good after debugging

the script and after it is working.

"Avishay Balderman" <avishay_...@bmc.com> wrote in message
news:urst9u5...@corp.supernews.com...

0 new messages