Solved

Determining if a user has selected text in Microsoft Outlook

Posted on 2004-04-26
7
283 Views
Last Modified: 2010-05-02
Is there a way to determine programmatically if a user has selected text in an Outlook message (i.e. email)?

I need to copy the text from an Outlook message (email).  Using the "SendKeys" command for "Select All" and "Copy", I can capture ALL text.  But if the user has selected or highlighted just part of the message, I only want to copy that portion.  If I can determine first if there is selected text, then I could omit the "Select All" command and only use the "Copy" command.  

Is there something, which can be checked using VB, that indicates if the user has selected part of the text?
0
Comment
Question by:TSClark251
  • 3
  • 2
  • 2
7 Comments
 
LVL 10

Accepted Solution

by:
ADSaunders earned 500 total points
ID: 10917269
Hi TSClark251,
You could copy regardless, and check whether anything was copied to the clipboard with:
if trim(clipboard.GetText) = "" then
(select all and copy)
End If

Regards .. Alan
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 10917637
Isn't this question in a wrong TA!?!?! Its a VB question!!!
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 10917668
TSClark251,

It is very very possible, but involves a lot of API calls. Are you ready to get into that? Okay, let me brief you on how to go about it.

1) Firstly you have to detemine whether such a window is open or not. Use FindWindow API call for the same. To use this call you will also need to know the window class of the window. You will have to use a tool like SPY++ to do the same. Or alternatively, you may find on the basis of the Window Title. If the call suceeds, it will return you the handle to the window, else the handle would be NULL.
2) If you successfully find the window, go ahead and find the control containing the message text. The approach would be similar to finding the main window.
3) Once you have the handle to the window instance containing the message text, you can easily get its selectedText property.

You see, this is possible, but requires some work.

Good luck!



~ Ranjeet Rain

0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 19

Expert Comment

by:RanjeetRain
ID: 10917676
Please ignore my first comment!
0
 

Author Comment

by:TSClark251
ID: 10924825
ADSaunders,

What an absolutely elegant solution.  I never considered a straightforward approach like this.  This not only works with Outlook, but also with any text window that permits Copy and Paste functions.
     
This is the actual code I ended up using:

     Clipboard.Clear
     'Copy User-Selected Text to the clipboard    
     SendKeys "^c", True                        
     'Check for presence of User-Selected Text    
     If Trim(Clipboard.GetText) = "" Then  
           'If none exists, then copy the entire document
           SendKeys "^a", True
           SendKeys "^c", True
     End If

Respectfully, T.C.
0
 

Author Comment

by:TSClark251
ID: 10924861
RanjeetRain,

Thanks for your input.   Fortunately I don't need to delve into API calls just yet...

r/ T.C.
0
 
LVL 10

Expert Comment

by:ADSaunders
ID: 10926064
Elegant Eh? .. Very Gracious of you .. Thanks

.. Alan
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

786 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