Search code examples
vbaexcelnotepad

Copy everything from an open notepad into a spreadsheet using VBA without having to save the notepad


There are some great resources to copy and paste a pre-existing notepad's data into an excel spreadsheet using VBA. I have not found anything to help with my issue though... I would like to copy and paste all the data from an open notepad into an excel spreadsheet, but due to the high volume of these notepads, I would like to not save them. Is there a way to do this.

I just need an idea of how to get started all other criteria etc I can work on from there... thanks in advance!


Solution

  • Since you are just asking for ideas, here are a few:

    • You can't rely on SendKeys. AppActivate will only take you halfway there and then you're lost
    • Instead you will need a few WinAPI calls, primarily FindWindow and SendMessage
    • The message you need most is WM_GETTEXT
    • If you don't know the exact window title, you will have to find a Hwnd or the exact title

    In the title you say Notepad, but in your comments you say Wordpad. The method on how to extract the text differs slightly.