SendKeys Question? VBA Excel-VBForums
Results 1 to 5 of 5

Thread: SendKeys Question? VBA Excel

  1. #1

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    SendKeys Question? VBA Excel

    Code:
    ' Run regedit in hiden mode and activate it
        Shell "C:\Windows\REGEDIT.EXE", vbHide
        AppActivate "Registry Editor"
        
        ' Make sure we start at root directory
        SendKeys "{LEFT}", True
    
        ' Navigate to Edit/Find menu and search for key
        SendKeys "%EF", True
        SendKeys "C:\PORTMG32\VBaddins\Backvb.xla"
        SendKeys "{ENTER}"

    How do I know if the search results are True or False?

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,482
    You won't be able to do tit this way. Sendkeys passes a keypress event accross to the active program, and generally, it's advisable to avoid calling the statement several times as above as it may take a while for the active program to carry out the passed keypress. I.e. take this example:
    VB Code:
    1. SendKeys "%EF", True
    2. SendKeys "C:\PORTMG32\VBaddins\Backvb.xla"
    3. SendKeys "{ENTER}"
    4. SendKeys "F3"

    Okay I don't know off the top of my head what the F3 key is, but in regitry editor if you want to perform a findnext, you would hit the f3 key, above, vb would execute this line straight after the initial find is requested (when you hit enter), it would not wait for the find to finish and find the first item before it ran the last line there requesting a find next.

    A second point on the sendkeys statement is you never know if the user switches across to another application which will change the focus - they could open notepad mid way through the above code execution so part of the code will be picked up by registry editor whilst the enter & F3 commands could be picked up by notepad leaving the user puzzled.

    This question is not that simple to do an example for & you might be better off asking this in the API forum.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,482
    Okay the API call you need to look for is RegEnumKeyEx to search through the registry for a key value. Try searching for this on either these forums or www.allapi.net.

    Good luck

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    Unhappy Too risky...

    I have given up my searching of the registry through regedit. Very scary stuff especially since this code will be used in corporations with millions of dollars tied up on their day to day trades. If I screw up something in their registry and something happens, it will fall on my head.

    Not worth the risk but thanks all

  5. #5
    Fanatic Member seec77's Avatar
    Join Date
    Jan 2003
    Posts
    596
    RegEnumKeyEx can not harm the system...
    for maximum protection, only define RegOpenKeyEx and RegEnumKeyEx, and if you use them one time, that means it will always work!
    Best Regards,
    seec77

    If you helped me, cosinder yourself thanked.

    Get each and every Garfield strip here!
    Here you can get all Calvin & Hobes strips!
    Damn UComics! It was probably unprofitable for them to allow us to just download Garfield and Calving & Hobes strips... so they made folder indexing unallowed on their server!!!

    I am 33% addicted to Counterstrike. What about you?
    I am 23% addicted to Star Wars. What about you?
    I am 0% addicted to Tupac. What about you?

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

Survey posted by VBForums.