|
-
Dec 25th, 2005, 02:22 PM
#1
Thread Starter
Fanatic Member
Retrieving the text from an open document, how to?
Hello!
I want to retrieve the text (and only the text) from the document that the
user is writing right now.
That means the text from Word, Excel and more apps (not just Office, maybe
OpenOffice as well...).
Anyone knows how to do this using c#?
thanks
-
Dec 25th, 2005, 02:26 PM
#2
Re: Retrieving the text from an open document, how to?
For your Office apps you could do something for each app but there would be allot of issues. Why does it need to be real-time? If it wasnt you could probably search documents etc. for any text your looking for.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 25th, 2005, 09:28 PM
#3
Re: Retrieving the text from an open document, how to?
I think that your best bet would be to use API functions, although I'm not sure it would be escpecially easy. I use a dictionary called WordWeb that allows you to select a word in any app and the press Ctrl+Alt+W to have WordWeb open with that word and its definition displayed. The way to do this in .NET would be to create a keyboard hook (a forum search will turn up info) to trap the desired key combination even when your app is not active, then use API functions to get the selected text from the active window in the active application. Note that active window means any window, not just a form. You would certainly use the GetForegroundWindow function, but beyond that I couldn't say for sure.
-
Dec 26th, 2005, 03:35 AM
#4
Re: Retrieving the text from an open document, how to?
GetForegroundWindow, and then it depends on the control. If it is a text box it will probably respond to a SendMessage with WM_GETTEXT. For Excel I have no idea.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|