Shell Execute Problem

I'm using the following code to bring up a new message in the user's default email program:

*************************************************
ShellExecute Me.hwnd, "open", "mailto:" & "xxx@xxx.com" _
            & "&Subject=The Subject" _
            & "&Body=Text Line 1 & vbCrLf _
            & "Text Line 2.", vbNullString, vbNullString, vbNormalFocus

*************************************************

As you can see, I'm trying to get a line break between Text Line 1 and Text Line 2 in the body of the email by inserting vbCrLf.
However, it doesn't work.
Any thoughts?
ianchAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Barry CunneyConnect With a Mentor Commented:
Hi Ianch,
I honestly don't know why this does not work properly in Outlook Express.
I am at work now - don't have Outlook Express installed on my work computer but have it on laptop at home - so I will test above with Outlook Express this evening when I get home.
I had thought that the 'malto' tag would be fairly standard across all mail applications.

Cheers

BCUNNEY
0
 
AmitabhCommented:
At first look (apologies in advance if i am wrong)

i think in line 3 you need to close the double quote (which u begin from &Body).
0
 
AmitabhCommented:
May be it should be something like that....

ShellExecute Me.hwnd, "open", "mailto:" & "xxx@xxx.com" _
           & "&Subject=The Subject" _
           & "&Body=Text Line 1" & vbCrLf _
           & "Text Line 2.", vbNullString, vbNullString, vbNormalFocus
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Ryan ChongCommented:
Not very sure but try replace VbCrlf with "\n" ?
0
 
andyleeceCommented:
try chr(13), it breaks a new line.
0
 
priya_pbkCommented:
hey guys i was just trying the above suggestions, does'nt seem to work for me!!

0
 
AmitabhCommented:
>>hey guys i was just trying the above suggestions, does'nt seem to work for me!!

hey priya,
i couldn't follow you, what have you tried? becoz we expected ianch to say something like this.
anyway shellexecute is a function i suppose and the lines after that are parameters to it. now what i think is that (as per the code which has a apparent mistake) a double quote is missing in line 3 so vbcrlf is being misconstrued as a string and not constant.

but where is ianch. we are looking for him if he has tried the suggestions above. or to know what exactly is the problem he is facing.

Regards,
A.Pandey
0
 
priya_pbkCommented:
Amitabh,

i guess, since everybody can try out giving suggestions, when i looked at this qt, maybe i thought I could help. But when I did see the full qt details, it was something new to me, coz i thought "ShellExecute" was usually used to run a particular exe. Therefore when I wrote a dummy project at my end, none of the above things worked for me.ie neithere vbcrlf nor \n nor Chr(13), that 's why was curious abt it. That's all!

No offence Amitabh, I think we are all here to learn and share knowledge!, right?

-priya
0
 
Barry CunneyCommented:
Hi Ianch
Try the following

ShellExecute Me.hwnd, "open", "mailto:" & "ccunnane@worldlinkits.com" _
          & "&Subject=The Subject" _
         & "&Body=Text Line 1%0D%0AText Line 2", vbNullString, vbNullString, vbNormalFocus
0
 
Barry CunneyCommented:
Hi Ianch
Was in a rush earlier on
Just to qualify
What I have inserted into &Body parameter above is
0D the HEX value 13 which is the ASCII value for CR
and also 0A which is HEX value for 10 ASCII value for LF
These have to be qualified with %
This is similar to the way you pass literal characters in to a URL.
Let me know if this works for you - I tested it with ShellExecute in VB and it worked for me.

Cheers
0
 
AmitabhCommented:
very Right priya...
had never intended to hurt you and never questioned why u said what u said.
infact i said that 'coz i couldn't understand ur statement. so i thought may be you could make it more clear, what actually is going at ur end so that it can be a value add to all of us.
hope u didn't misunderstand me....
looking for your cooperation and support in EE....

With Regards,
0
 
priya_pbkCommented:
>>hope u didn't misunderstand me....
looking for your cooperation and support in EE....<<

no problem!! I dont think anybody should take the suggestions given personally, atleast i don't :0). We are here to help one another for learning new things and share those with others.

And 'BCUNNEY'
your suggestion sure seems to work! was wondering if one does not know the hex of a particular value can that be substitued by the function in vb ie

syntax:-
Hex(Number) 'which takes number as parameter

I tried this, but does 'nt seem to work!
Hex(Asc(vbCrLf))

And one more thing, how come the vbcrlf and \n or chr(13) does 'nt seem to work. If you dont mind, can i have some info abt this?

-priya
0
 
Barry CunneyCommented:
Hi priya(and Ianch)
Intersting thought about using Hex function
With your idea I got the below to work.
*************************************************
Dim HexCr
Dim HexLf
Dim HexCrLf

HexCr = "%0" & Hex(Asc(vbCr))
HexLf = "%0" & Hex(Asc(vbLf))
HexCrLf = HexCr & HexLf

ShellExecute Me.hwnd, "open", "mailto:" & "ccunnane@worldlinkits.com" _
         & "&Subject=The Subject" _
        & "&Body=Text Line 1" & HexCrLf & "Text Line 2", vbNullString, vbNullString, vbNormalFocus
*******************************************************
I am not fully sure why /n or chr(13) doesn't work.

Just I had come across similar solution before to a problem similar to Inach's before.
We wer writing a program in C++ and dynamically creating a URL. One parameter in this was a phone number in the form +4434044044 but because the '+' is like a reserved symbol in URL terms our phone number was not validly being passed - so we came across the tip somewhere on the 'web' of passing in the Hex(Ascii) value of character qualified by %.
Obviously the 'mailto:' tag is similar to a URL or hyperlink.
Possibly some of the experts in the ASP or Javascript area would be able to give the core explanation as to why the Hex of ASCII code works. My knowledge is not that deep in this area but if I come across anything I will post it.

Cheers

Bcunney

0
 
priya_pbkCommented:
Thanks Bcunney for that update and glad to know you got an idea from me. :0) Actually I was trying it out at vb, since i was sure that an Hex function exists. But I did not know that "%0" should be concatenated with the Hex function.

One more thing, why is the Cr and Lf separated and not taken together like hex(asc(vbcrlf) as i was trying.? As far as i know LF is for line feed!

-priya




0
 
Barry CunneyCommented:
priya,
The vbCrLf constant is in effect is made up of two characters with ascii codes 13 and 10 respectively.
The ASC function when applied to a string of more than one character returns the ASCII code of the first character in the string. See this example code from MSDN

Dim MyNumber
MyNumber = Asc("A")   ' Returns 65.
MyNumber = Asc("a")   ' Returns 97.
MyNumber = Asc("Apple")   ' Returns 65.

Therefore ASC(vbCrlf) only returns 13 and the HEX of this is not enough to provide a carriage return and a line feed as in the case above.

This is MSDN definition of ASC function

Returns anInteger representing thecharacter code corresponding to the first letter in a string.

Cheers

BCUNNEY

P.S. I wonder where ianch is??




0
 
Barry CunneyCommented:
T
0
 
Barry CunneyCommented:
This is another variation on how one could construct the crlf hex variable

HexCrLf = "%0" & Hex(Asc(Left(vbCrLf, 1))) & "%0" & Hex(Asc(Right(vbCrLf, 1)))
0
 
priya_pbkCommented:
Thanks BCUNNEY! seems Ianch is the only one who is not updated, rest of us surely have been!
0
 
ianchAuthor Commented:
Hi BCUNNEY,
Your solution works fine. Thank you.
Can you enlighten me on one more thing.
This code seems to put everything in the right place
if Microsoft Outlook is my default email program,
but if I change to Outlook Express the subject and body
all go into the To Box
0
 
ianchAuthor Commented:
Just a little add on :
If I use Netscape messenger as my default it does the same as Outlook Express. ie: Puts everything in the email address box.
0
 
ianchAuthor Commented:
Thanks for all to BCUNNEY
I found out if we change the & to a ? before Subject
it works for all.
Ian
0
 
Barry CunneyCommented:
Ianch
Glad to hear you got problem resolved with Outlook Express.
I had tested it with Outlook Express last night and seen the problem you were getting with everything put in the To field - but I could not figure out what problem was - it was late, and after a along day.


Cheers

BCUNNEY






0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.