?
Solved

Determining if a user has selected text in Microsoft Outlook

Posted on 2004-04-26
7
Medium Priority
?
290 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
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 10

Accepted Solution

by:
ADSaunders earned 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 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