+ Reply to Thread
Results 1 to 9 of 9

Using SendKeys, sending keys to different workbooks

  1. #1
    Registered User
    Join Date
    07-17-2020
    Location
    pakistan
    MS-Off Ver
    2019
    Posts
    5

    Using SendKeys, sending keys to different workbooks

    Salam (Blessings) out there!
    I'm using sendkeys function in excel macro to send keys to different workbooks. But only one workbook is getting all the keys. Here is the sample code:

    Please Login or Register  to view this content.
    I'm running this code from book1.
    As per my knowledge, if everything goes right, than book2 must receive the keys abc, and book1 def. But here excel sending all of the keys i.e. "abcdef" to the book1.
    If we remove the line:
    AppActivate "book1 - excel"
    than excel passes the keys to book2.
    What I trying to achieve is that activate a specific workbook or sheet, pass set of keystrokes to it, activate another, pass keystrokes to it and so on.....
    I'm pretty much new at excel macros and vba code. So, unable to figure out the problem.
    Any help is appreciated.....
    Thanks in advance.
    Last edited by AliGW; 07-18-2020 at 04:20 AM.

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,307

    Re: Using SendKeys, sending keys to different workbooks

    The code works as you expected on my system.

  3. #3
    Registered User
    Join Date
    07-17-2020
    Location
    pakistan
    MS-Off Ver
    2019
    Posts
    5

    Re: Using SendKeys, sending keys to different workbooks

    First of all thanks for your reply.
    Any idea why it is not working on my system?
    windows 10 pro v1909 and office 2019?

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,307

    Re: Using SendKeys, sending keys to different workbooks

    Possibly, if the workbook has been saved, it may need the full name of the workbook?

  5. #5
    Registered User
    Join Date
    07-17-2020
    Location
    pakistan
    MS-Off Ver
    2019
    Posts
    5

    Re: Using SendKeys, sending keys to different workbooks

    Thanks once again for ur reply.
    Tried it with the full name, even tried with windows ("workbookName").activate method, but no luck!
    I also tried this code on a friends computer who have office 365 subscription, even on his computer it doesn't work....
    Anything else?
    If only one workbook is open, or if we have to send keys to only one workbook, than there is no problem, but as soon as two or more workbooks involves, don't know why excel mysteriously send keys to only one workbook of its choice.....
    If we have multiple programs to send keys, like sap, word calculator etc, even than no problemm. Only with sending keys to two or more workbooks.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,480

    Re: Using SendKeys, sending keys to different workbooks

    Try putting in some doevents.

    Please Login or Register  to view this content.
    Whilst I can see using sendkeys to control non Office apps may be necessary, if you are wanting to manipulate other workbooks I would suggest using the object model rather than sendkeys.
    Cheers
    Andy
    www.andypope.info

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,202

    Re: Using SendKeys, sending keys to different workbooks

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are new here, I have done it for you this time.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  8. #8
    Registered User
    Join Date
    07-17-2020
    Location
    pakistan
    MS-Off Ver
    2019
    Posts
    5

    Re: Using SendKeys, sending keys to different workbooks

    Andy Thanks for your reply.
    Working now. How? don't have any clue.
    And yes-I agree, for manipulating workbooks object model is best, but as I said before I'm just a beginner and currently don't have enough time to dig into those valleys. At work, part of my job is filtering data from different excel sheets and putting them into SAP. And I'm figuring out if I might automate this system, and focus on more serious tasks....
    And Dude you just made it possible!
    So, Thanks once again.....
    Stay blessed!

  9. #9
    Registered User
    Join Date
    07-17-2020
    Location
    pakistan
    MS-Off Ver
    2019
    Posts
    5

    Re: Using SendKeys, sending keys to different workbooks

    Thanks Ali for your comments. Will remember these from now on....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. IE automation VBA, delay in sending keys, using sendkeys instantly
    By sairakeshraj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2012, 01:43 PM
  2. SendKeys not sending the key when I want it to
    By niko79542 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2012, 03:20 PM
  3. Sending e-mail - Alternative to SendKeys and Wait?
    By Phil_V in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-19-2011, 07:05 PM
  4. Getting Sendkeys to Send Keys
    By starcraftbud in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-10-2011, 01:21 PM
  5. [SOLVED] Sending Keys from Excel to Internet Explorer
    By matt in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-18-2006, 01:25 PM
  6. Sending Ctrl-Alt-Del Keys
    By clu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2006, 10:25 AM
  7. [SOLVED] Sending keys to DocuCom PDF Driver
    By TroyH in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-13-2005, 07:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1