PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming Problem of sending content with links in Word to Outlook

Reply

Problem of sending content with links in Word to Outlook

 
Thread Tools Rate Thread
Old 04-12-2007, 10:13 AM   #1
LEE
Guest
 
Posts: n/a
Default Problem of sending content with links in Word to Outlook


I have a word file with VBA to save the content to Draft in Outlook. It works
but the link in the content change to text rather than link even if it is
actually a link in Word and I have set the mail format to HTML in Outlook. I
find the end of each line in the draft mail contain a space and the link
recovers if I delete the ending space. Grateful if you can help with the
following word VBA.

Private Sub CreateOutlookMessage()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem

On Error GoTo ErrorMsgs

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olDraftItem)
With objOutlookMsg
.To = "test@xxxxx.com"
.Subject = "test"
.BodyFormat = olFormatHTML
.Body = ActiveDocument.Content
.Save
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
Exit Sub

ErrorMsgs:
If Err.Number = "287" Then
MsgBox "You clicked No to the Outlook security warning. " & _
"Rerun the procedure and click Yes to access e-mail" & _
"addresses to send your message. For more information, " & _
"see the document at http://www.microsoft.com/office" & _
"/previous/outlook/downloads/security.asp. "
End If
End Sub
  Reply With Quote
Old 04-12-2007, 01:15 PM   #2
Sue Mosher [MVP-Outlook]
Guest
 
Posts: n/a
Default Re: Problem of sending content with links in Word to Outlook

Setting the format to HTML doesn't automatically create hyperlinks or other HTML formatting features. If you want HTML content, you would need to set HTMLBody, not Body to the fully tagged HTML content.

An easier approach is to use the "Office envelope" technique: http://www.outlookcode.com/codedetail.aspx?id=1333

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"LEE" <LEE@discussions.microsoft.com> wrote in message news:941604EC-303B-4510-BD70-1E83D9B79BE4@microsoft.com...
>I have a word file with VBA to save the content to Draft in Outlook. It works
> but the link in the content change to text rather than link even if it is
> actually a link in Word and I have set the mail format to HTML in Outlook. I
> find the end of each line in the draft mail contain a space and the link
> recovers if I delete the ending space. Grateful if you can help with the
> following word VBA.
>
> Private Sub CreateOutlookMessage()
> Dim objOutlook As Outlook.Application
> Dim objOutlookMsg As Outlook.MailItem
>
> On Error GoTo ErrorMsgs
>
> ' Create the Outlook session.
> Set objOutlook = CreateObject("Outlook.Application")
> ' Create the message.
> Set objOutlookMsg = objOutlook.CreateItem(olDraftItem)
> With objOutlookMsg
> .To = "test@xxxxx.com"
> .Subject = "test"
> .BodyFormat = olFormatHTML
> .Body = ActiveDocument.Content
> .Save
> End With
> Set objOutlookMsg = Nothing
> Set objOutlook = Nothing
> Set objOutlookRecip = Nothing
> Set objOutlookAttach = Nothing
> Exit Sub
>
> ErrorMsgs:
> If Err.Number = "287" Then
> MsgBox "You clicked No to the Outlook security warning. " & _
> "Rerun the procedure and click Yes to access e-mail" & _
> "addresses to send your message. For more information, " & _
> "see the document at http://www.microsoft.com/office" & _
> "/previous/outlook/downloads/security.asp. "
> End If
> End Sub

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off