Results 1 to 4 of 4

Thread: Retrieving the text from an open document, how to?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Question 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

    Dekel C.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width