Determining if a user has selected text in Microsoft Outlook

Posted on 2004-04-26
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?
Question by:TSClark251
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
LVL 10

Accepted Solution

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
LVL 19

Expert Comment

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

Expert Comment

ID: 10917668

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

LVL 19

Expert Comment

ID: 10917676
Please ignore my first comment!

Author Comment

ID: 10924825

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:

     '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.

Author Comment

ID: 10924861

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

r/ T.C.
LVL 10

Expert Comment

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

.. Alan

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

Suggested Solutions

Title # Comments Views Activity
VB6 / DAO 3.6 / run time error: Couldn't find installable ISAM 7 119
SSRS expression Issue finding a string 10 101
Validating VB6 Function 19 68
TT Auto Dashboard 13 101
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

730 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