Consulting

Results 1 to 5 of 5

Thread: simulating keystrokes

  1. #1
    VBAX Newbie
    Joined
    Aug 2010
    Posts
    3
    Location

    simulating keystrokes

    Hi all,
    I've got a sheet of data and I need to take this data one cell at a time and copy it into a non microsoft program and then simulate keystokes inside that software from my macro. Is there anyway of doing this?

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Sendkeys() would be the first option. That method should always be your last choice though. SendKeys() will not work when Vista's or Win7's UAC is on. You can use alternative programs like AutoIt to send keys irregardless of UAC status. I have written a vb.net EXE file that can do it as well. SendKeys() methods rely on focus and timing. This can be tricky at times.

    Some other applications allow access to their object model. That method depends on the application of course.

  3. #3
    VBAX Newbie
    Joined
    Aug 2010
    Posts
    3
    Location
    Quote Originally Posted by Kenneth Hobs
    Sendkeys() would be the first option. That method should always be your last choice though. SendKeys() will not work when Vista's or Win7's UAC is on. You can use alternative programs like AutoIt to send keys irregardless of UAC status. I have written a vb.net EXE file that can do it as well. SendKeys() methods rely on focus and timing. This can be tricky at times.

    Some other applications allow access to their object model. That method depends on the application of course.
    Here is the basic idea.

    I am having data provided to me via xls.

    That data will then be cleaned up by my macro.

    I will then need to preform tasks with this data in another program.
    I will need to copy the account number, paste it into my software and hit search. Click a few buttons in said software. Clear the account and move to the next.

  4. #4
    VBAX Newbie
    Joined
    Aug 2010
    Posts
    3
    Location
    I've done some more research on this, please tell me if I am on the right path here

    I would use AppActivate() to place the focus on the application I need and the I would use SendKey() to emulate the keys to this application?

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    There is alot more to it but to some extent , yes. Use SendKeys() as there is no SendKey(). API commands offer some other options.

    e.g.
    [VBA]Sub SavePartcorrect()
    Dim myPath As String, txtPath As String
    Dim rc As Long
    Dim wb As Workbook

    Set wb = ActiveWorkbook
    myPath = ThisWorkbook.Path & "\"
    txtPath = myPath & "Test.txt"

    rc = Shell("NOTEPAD.EXE " & txtPath, vbNormalFocus)
    AppActivate rc
    Application.Wait Now + TimeValue("00:00:01")
    SendKeys Application.UserName, True
    SendKeys "{Enter}", True
    End Sub[/VBA]

    Here are some API methods to give you an idea of other possibilities. Put this code in a Module. http://vbaexpress.com/forum/showthread.php?t=26601

Posting Permissions

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