Solved

Launch OutLook

Posted on 2004-04-22
15
732 Views
Last Modified: 2012-05-04
Hi all

I in my program, I want to launch OutLook and put something in the body of mail.
I do like that:

'Declare
Private Const SW_SHOW = 1

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

'*******************
Sub Navigate(ByVal NavTo As String)
    Dim hBrowse As Long
    hBrowse = ShellExecute(0&, "open", NavTo, "", "", SW_SHOW)    
End Sub

Then I call Navigate like that:

Navigate "mailto:someone@somewhere.com?subject=" & _
                            "My subject&body=" & _
                            strText1 & vbCrLf & strText2

I insert vbCrlf because I want an empty line between strText1 and strText2. But it don't has any effect.
How can I insert an empty line between strText1 and strText2?





0
Comment
Question by:melodiesoflife
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
15 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 250 total points
ID: 10886362
Hi melodiesoflife,

Try replacing vbCrLf with "escaped" characters for Carriage Return & Line Feed.

e.g.

Navigate "mailto:someone@somewhere.com?subject=" & _
                            "My subject&body=" & _
                            strText1 & "%0B%08" & strText2

The prefix of "%" indicates the values are in Octal.

BFN,

fp.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 10886425
You can try create a User Form, where the user can type in the info like : Receiver, Receiver Name, Subject, Body Message, Attahment, etc into the form. Then try add the M$ Outlook Object Library in order to send out the email:

Example on the "Send Now" button:

Private Sub cmdSendNow_Click()
    Dim iOutlook As Outlook.Application
    Dim myApp As Outlook.MailItem
    Set iOutlook = New Outlook.Application
    Set myApp = iOutlook.CreateItem(olMailItem)
    temp = "Username"
    txtMessage = "Hello World Again!"
    AttachFile = "C:\Documents and Settings\Administrator\My Documents\My Pictures\next.gif"
    myApp.To = "user@domain.com"
    myApp.Subject = "Hello World!"
    myApp.Attachments.Add AttachFile
    myApp.Body = "Hi " & temp & vbCrLf & vbCrLf & txtMessage
    'myApp.HTMLBody = ""
    myApp.Send
    Do While iOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderOutbox).Items.Count <> 0
        DoEvents
    Loop
    MsgBox "Successfully Sent", vbInformation, "Email Sent"
End Sub

Customize the example above to suit your requirement, i think this will be the most effective way to present your application.

Hope this helps
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 10886441
Should it be "%0B" instead of "%0B%08"?  fanpages ;-)
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10886622
First one is "%0B" (that's capital "b" as this is the octal code for decimal 13 - a carriage return), the second one is "%08" - the octal code for line feed (decimal 10).

Together you get <CR><LF>.

If you just want a <CR> use "%0B" or just a <LF> use "%08".

BFN,

fp.
0
 
LVL 6

Author Comment

by:melodiesoflife
ID: 10886727
Hi fanpages

I have try but it don't effect.
When strText1 = "a" and strText2 = "b" I hope the result in outlook is:

a
b

but it show a strange character: a b

'***************************************

Hi ryancys

When use Outlook.Application and so on, I must register library before used but I can't find it, where it is?
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10886784
Hi,

Is your MS-Outlook e-mail set to HTML format as default?

BFN,

fp.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10886808
Sorry... may just be a "quirk" of MS-Outlook.

I tried two %0B characters & this seemed to be OK!

mailto:someone@somewhere.com?subject=My subject&body=body%0B%0Bbody2

Results in:

===
body

body2
===

In the message text.

BFN,

fp.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 10889797
>>When use Outlook.Application and so on, I must register library before used but I can't find it, where it is?
In the case you need to use Outlook Objects in your application, you Must include the Library from the References, you Should able to find the M$ Outlook Object Library from References (goto menu Project > References) IF you installed the M$ Outlook in your machine.
0
 
LVL 6

Author Comment

by:melodiesoflife
ID: 10890427
Hi ryancys

I installed the MS Outlook, but I don't see Outlook Object Library in Referrences dialog.

Do you have any suggest
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10890508
Hi again,

Did:

mailto:someone@somewhere.com?subject=My subject&body=body%0B%0Bbody2

Not work?

Or are you just trying alternate method(s)?

BFN,

fp.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 10890610
Try find the "Microsoft Outlook 9.0 Object Library" from References (10.0 for XP, etc)

if still Not found, simply click the Browse, the go to:

<Office or Outlook install folder>\Office\MSOUTL9.OLB (9.0, for 10.0 look for something like MSOUTL10.OLB)

Example:

C:\Program Files\Office2000\Office\MSOUTL9.OLB

select the file then click the Open button. And Now the Library should added to the list.

regards
0
 
LVL 6

Author Comment

by:melodiesoflife
ID: 10895731
Hi  ryancys.

well, I see. But what happen if my customer's computer don't install  MS Office (I see that MSOUTL9.OLB is installed when I install MS Outlook).
I only want to use Outlook Express, which included in Window, I don't want to install anythings else.

'********************

Hi fanpages.

mailto:someone@somewhere.com?subject=My subject&body=body%0B%0Bbody2

I don't know why but it still not work.
0
 
LVL 6

Author Comment

by:melodiesoflife
ID: 10895978
Hi fanpages

I found it. not %0B%08. It must %0D%0A.

That mean 13 and 10 in hexa
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10896544
Hi,

Glad you found a solution in the end.

Yes, I would ordinarily use ASCII code 13 (decimal) for <CR> & 10 (decimal) for <LF>.

In fact there are too in-built VB/VBA constants vbCR & vbLF (and also vbCRLF) that are set to these values; you may like to use those.


The %0B%0B [double zero 'B'] works via HTML!?!

Yet another Micro$o£t oddity.

Thanks for the points/grading.

Happy codin',

BFN,

fp.
[http://NigelLee.info]
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 10896693
>>But what happen if my customer's computer don't install  MS Office
Ya, that's the sad place, if you can use the Outlook Library, sure your presentation will be better.

or you can try use this free component to send mail instead:
vbSendMail.dll Version 3.65-- Easy E-mail Sending in VB, with Attachments
http://www.freevbcode.com/ShowCode.Asp?ID=109

cheers
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question