dcsimg
Results 1 to 4 of 4

Thread: How to use sendkeys command for a specific application running in background

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2019
    Posts
    2

    Smile How to use sendkeys command for a specific application running in background

    Hi everyone,

    I use a loop to copy and paste data from an APP and the code I use is as below.

    Since I use appactivate command everytime vba focus app window and copy-paste value from a specific part.

    Is that possible to code so vba can do this action in background without focusing this app ?

    *
    AppActivate "APPNAME"
    SendKeys "^c"
    Application.Wait (Now + TimeValue("0:00:01"))
    Sheets("SHEETNAME").Cells(4, 4).Select
    ActiveSheet.Paste

    *

    Thank you

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,447

    Re: How to use sendkeys command for a specific application running in background

    not with sendkeys

    you would have to use some APIs to find the correct window and the correct control or position in the window
    then use sendmessage API to insert the string
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2019
    Posts
    2

    Re: How to use sendkeys command for a specific application running in background

    Quote Originally Posted by westconn1 View Post
    not with sendkeys

    you would have to use some APIs to find the correct window and the correct control or position in the window
    then use sendmessage API to insert the string
    Thank you for the explanation.

    Do you have any simple sample for similar case ?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,447

    Re: How to use sendkeys command for a specific application running in background

    have a look at this thread, though the examples are more to put a value into some window rather then read from, but if you can find the right window and child window that is most of the battle

    http://www.vbforums.com/showthread.p...97#post5349897
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width