Solved

Determining if a user has selected text in Microsoft Outlook

Posted on 2004-04-26
7
281 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
Comment Utility
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
Comment Utility
Isn't this question in a wrong TA!?!?! Its a VB question!!!
0
 
LVL 19

Expert Comment

by:RanjeetRain
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 19

Expert Comment

by:RanjeetRain
Comment Utility
Please ignore my first comment!
0
 

Author Comment

by:TSClark251
Comment Utility
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
Comment Utility
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
Comment Utility
Elegant Eh? .. Very Gracious of you .. Thanks

.. Alan
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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 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…

762 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

8 Experts available now in Live!

Get 1:1 Help Now