Results 1 to 13 of 13
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Application.SendKeys (XL97; SR2)

    I'm having an issue where I use Application.SendKeys to trigger a process where data is being loaded into an application. There seems to be a timing issue when any other code is used immediately after (the data will not load into the application) Application.SendKeys. If no other code is placed afterwards, everthing works just fine. I've tried using a wait command to allow plenty of time for the data to get to the application but still encounter the issue. Is there some code that will wait until the sendkey process is completed?

    Thanks,
    John

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.SendKeys (XL97; SR2)

    <pre></pre>

    If you do a search on the Lounge on SendKeys, I think you'll find that most people find it rather problematic. Personally, the few times I do use it are for procedures where it is the only code.
    Can you clarify a bit what you are actually attempting to trigger through using SendKeys? There may be practical workarounds.
    Gre

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.SendKeys (XL97; SR2)

    To clarify, I'm able to load information from an XL file into a database. The "SendKeys" code is used to envoke the appropriate keystrokes to load the information into a database. The issue as I see it may be related to how long it takes the data to be loaded in to the database. If I put any code such as changing a sheet, wait command or any other code the data will not load,

    Thanks,
    John

  4. #4
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.SendKeys (XL97; SR2)

    Not being clear as to what kind of database interface you have. Three alternatives spirng to mind - some of which may not apply.

    <UL><LI>Automating access to the front end using the MS Windows Scripting Host;<LI>Using a freeware Automation routine such as AutoIt (the scripting of which is slightly simpler than WSH);<LI>Automating the database front-end itself. (You may have already looked at this.)[/list]Both of the first two suggestions allow SendKeys with specifiable wait times; which it sounds like what you are looking for (as opposed to the Excel default).

    The issue may be of course that you are actually looking to do more processing inside Excel - rather than handing off to a SendKeys as a closing step - in which case the first two suggestions become somewhat problematic.

    I can't remember at the moment whether the WSH is also available as a reference from within XL97 (I mostly use 2000). In any event, it may not be the case that specifiable wait times can be achieved through WSH from inside Excel.

    Hope this helps
    Gre

  5. #5
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.SendKeys (XL97; SR2)

    <pre></pre>

    There is a Timer event that applies in Access - see this post. The Excel VBA Help mentions it also. NOT that I have first-hand experience of it, but it may be something worth looking at. In any event, I would be interested in your posting back on this. HTH
    Gre

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Application.SendKeys (XL97; SR2)

    That isn't a timer event, it's a call to the VBA Timer() function. DoEvents is also a VBA function that allows other processes to continue. Watch out for it in a multiuser environment, though, because it can bite you unexpectedly.
    Charlotte

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.SendKeys (XL97; SR2)

    Thank you. May I apologise for sloppy use of language.
    Gre

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Application.SendKeys (XL97; SR2)

    No need to apologize. There is a timer event on Access forms and I didn't want there to be any confusion between the various references to timers.
    Charlotte

  9. #9
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.SendKeys (XL97; SR2)

    Can someone clarify how the "DoEvents" works within the timer. After reading the help file documents within XL I'm no closer to understanding it.

    Thanks,
    John

  10. #10
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.SendKeys (XL97; SR2)

    I'm still confused on how the "DoEvents" works within the code.

    Example Code:
    Sub Start()
    Sheets("Sheet3").select
    Application.SendKeys "%(XE)" 'code I use to populate a database
    'There seems to be a timing issue with the SendKeys not completing it's task prior to selecting Sheet1. If I put a "DoEvents" here, I still have the timing problem.
    Sheets("Sheet1").select
    End Sub

    Your assistance is appreciated,
    John

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.SendKeys (XL97; SR2)

    Ok, I'm gonna take the bait.

    1) DoEvents tells the host application -- in your case Excel -- to stop processing the thread(s) of execution it initiated and allow the OS to process any "waiting" requests from other apps.

    2) Pitch the Sendkeys solution. Be a bit more specific about the data source. You can do what you want a better way.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  12. #12
    Star Lounger
    Join Date
    Aug 2001
    Location
    GA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.SendKeys (XL97; SR2)

    Have you tried passing TRUE as the 'Wait' arg. with the Sendkeys?

    Application.SendKeys("%(XE)", TRUE)

    By passing 'TRUE' Microsoft Excel wait for the keys to be processed before returning control. False (or omitted) to continue running the code without waiting for the keys to be processed.

    My 2 cents, If your app is going to be used by others, you should rethink your project and come up with another solution than using the SendKeys.
    In my early programming, using SendKeys, inevitably made my phone ring.
    I haven't used Sendkeys in over three years.
    Later,
    Bruce

  13. #13
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.SendKeys (XL97; SR2)

    I just could not help echoing this sentiment:

    >>rethink your project and come up with another solution than using the SendKeys.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

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