D
Darin
I am trying to attach an unsaved [active] document to an email message. In
addition, I want to prepopulate the To field with the various email addresses
in a bookmark of the document. I have successfully written the code to do
this only if the file is saved. Is there some way else to do this without
saving the file? if not, as i mentioned, i have successfully done this if it
is saved locally, but cannot get the same code to work if the document is
saved to a document management system [PC Docs]. Here is my code:
Dim sEmailAddress As String
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
'''this checks to see if the active document has been saved at least once
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)
'''go to EmailAddress bookmark to get e-mail addresses for email
Selection.GoTo What:=wdGoToBookmark, Name:="EmailAddress"
sEmailAddress = Selection.Text
With oItem
'''this is where the stored e-mail address is used for populating the message
.To = sEmailAddress
'''this is where you can customize the subject and body of e-mail message
'.Subject = "New subject"
'.Body = "Body text goes here."
'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
oItem.Display
If bStarted Then
oOutlookApp.Quit
End If
'''clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
'''close Send E-memo form
Unload Me
End Sub
addition, I want to prepopulate the To field with the various email addresses
in a bookmark of the document. I have successfully written the code to do
this only if the file is saved. Is there some way else to do this without
saving the file? if not, as i mentioned, i have successfully done this if it
is saved locally, but cannot get the same code to work if the document is
saved to a document management system [PC Docs]. Here is my code:
Dim sEmailAddress As String
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
'''this checks to see if the active document has been saved at least once
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)
'''go to EmailAddress bookmark to get e-mail addresses for email
Selection.GoTo What:=wdGoToBookmark, Name:="EmailAddress"
sEmailAddress = Selection.Text
With oItem
'''this is where the stored e-mail address is used for populating the message
.To = sEmailAddress
'''this is where you can customize the subject and body of e-mail message
'.Subject = "New subject"
'.Body = "Body text goes here."
'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
oItem.Display
If bStarted Then
oOutlookApp.Quit
End If
'''clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
'''close Send E-memo form
Unload Me
End Sub