Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Help needed with Mailto: command

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Angela 'Angel' Brown - 26 Oct 2005 14:02 GMT
Can the mailto command use strings and variavbles from inside the word
document?
e.g.

have a block of text once in a document and reference this text in the
mailto: command so that many mailto: command can use the same bit of text and
then the full text be in the email (not just a link to the text in the
document.)

Thank You
Karl E. Peterson - 26 Oct 2005 18:31 GMT
> Can the mailto command use strings and variavbles from inside the word
> document?
[quoted text clipped - 4 lines]
> text and then the full text be in the email (not just a link to the
> text in the document.)

Yep, it can be done, but there is a limit on the overall length.  I want to say it's
around 2000 chars, but can't recall precisely.  You build the mailto URL from your
strings/variables, something like this:

  Private Sub PrepareEmail(ByVal AddrTo As String, ByVal AddrCc As String, ByVal
Subject As String, ByVal Body As String)
     Dim Link As String
     Link = "mailto:" & AddrTo & _
            "?cc=" & AddrCc & _
            "&subject=" & Subject & _
            "&body=" & EscapeURL(Body)
     Call OpenDoc(Link)
  End Sub

The two helper functions there prepare the body text for use in a URL and actually
execute the link:

  Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA"
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal
lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  Private Declare Function UrlEscape Lib "Shlwapi.dll" Alias "UrlEscapeA" (ByVal
pszURL As String, ByVal pszEscaped As String, ByRef pcchEscaped As Long, ByVal
dwFlags As Long) As Long

  Private Const URL_DONT_ESCAPE_EXTRA_INFO As Long = &H2000000

  Private Function EscapeURL(ByVal URL As String) As String
     ' Purpose:  A thin wrapper for the URLEscape API function.
     Dim EscTxt As String
     Dim nLen As Long

     ' Create a maximum sized buffer.
     nLen = Len(URL) * 3
     EscTxt = Space$(nLen)

     If UrlEscape(URL, EscTxt, nLen, URL_DONT_ESCAPE_EXTRA_INFO) = 0 Then
        EscapeURL = Left$(EscTxt, nLen)
     End If
  End Function

  Private Function OpenDoc(ByVal DocFile As String) As Long
     Dim nRet As Long
     ' Actually uses the default verb if available, and "open" otherwise
     nRet = ShellExecute(0&, vbNullString, DocFile, vbNullString, vbNullString,
vbNormalFocus)
     Debug.Print "ShellExecute: "; nRet
     OpenDoc = nRet
  End Function

Later...   Karl
Signature

Working Without a .NET?
http://classicvb.org/petition

Angela 'Angel' Brown - 27 Oct 2005 07:07 GMT
Captain EO - 28 Oct 2006 05:30 GMT
Hi Karl

Wondering if you can help me.

I am using mailto in a URL.  Basically I want the URL to open outlook --
this is working fine.  However I want the email created to include my outlook
signature, but when I use mailto I get a blank email even though I have
signatures turned on. Any ideas on how I can get the signature into the email.

Thanks.

> > Can the mailto command use strings and variavbles from inside the word
> > document?
[quoted text clipped - 55 lines]
>
> Later...   Karl
Doug Robbins - Word MVP - 28 Oct 2006 08:22 GMT
Here is one way of doing it, but it may require that you have two email
accounts set up in Outlook.  In the Outlook message pane, there is a button
that allows you to select the account from which the message will be sent.
Changing the account inserts/changes the signature to the one that you have
set up for the account that is selected.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi Karl
>
[quoted text clipped - 79 lines]
>>
>> Later...   Karl
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.