Solved

Shell Execute Problem

Posted on 2002-07-24
22
638 Views
Last Modified: 2012-06-21
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?
0
Comment
Question by:ianch
  • 8
  • 5
  • 4
  • +3
22 Comments
 

Expert Comment

by:Amitabh
ID: 7173628
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
 

Expert Comment

by:Amitabh
ID: 7173630
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7173635
Not very sure but try replace VbCrlf with "\n" ?
0
 

Expert Comment

by:andyleece
ID: 7173642
try chr(13), it breaks a new line.
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7173735
hey guys i was just trying the above suggestions, does'nt seem to work for me!!

0
 

Expert Comment

by:Amitabh
ID: 7173760
>>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
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7173789
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
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 7173871
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
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 7173902
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
 

Expert Comment

by:Amitabh
ID: 7173975
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
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7174004
>>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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:Barry Cunney
ID: 7174363
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
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7174965
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
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 7175083
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
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 7175088
T
0
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 7175090
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
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7175116
Thanks BCUNNEY! seems Ianch is the only one who is not updated, rest of us surely have been!
0
 

Author Comment

by:ianch
ID: 7175979
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
 

Author Comment

by:ianch
ID: 7176004
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
 
LVL 17

Accepted Solution

by:
Barry Cunney earned 100 total points
ID: 7176697
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
 

Author Comment

by:ianch
ID: 7179058
Thanks for all to BCUNNEY
I found out if we change the & to a ? before Subject
it works for all.
Ian
0
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 7179733
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now