Consulting

Results 1 to 9 of 9

Thread: Solved: Sendkeys using wait.

  1. #1
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location

    Solved: Sendkeys using wait.

    Hi all

    I'm trying to use the Sendkeys appplication. In the help it says you can tell it to wait until the process has finished before handing control back to the macro. I've tried various sytax's but can't get the damned thing accepted (Compile Error. Expected: =)

    Any ideas?

    Best regards

    Paul Ked
    Semper in excretia sumus; solum profundum variat.

  2. #2
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Paul,
    Show us the code you are having trouble with please.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Quote Originally Posted by lucas
    Hi Paul,
    Show us the code you are having trouble with please.
    [vba]Sub SaveFile()
    Dim SavePath As String
    Dim LYear As Integer
    Dim LWeek As String
    Dim fso
    Dim fol As String
    Application.SendKeys ("%me") '("%me",WAIT) Want to wait Here!
    Application.SendKeys ("{ENTER}") '("%me",-1) And Here
    !
    Sheets("Main").Select
    Sheets("Main").Copy
    Sheets("Main").Select
    Sheets("Main").Name = "Sheet1"
    LYear = Year(Date)
    LWeek = DatePart("ww", Now())
    fol = "C:\Ovens\Records\" & LYear
    Set fso = CreateObject("Scripting.FileSystemObject")
    If Not fso.FolderExists(fol) Then
    fso.CreateFolder (fol)
    End If
    fol = fol & "\" & "Week " & LWeek & "\"
    If Not fso.FolderExists(fol) Then
    fso.CreateFolder (fol)
    End If
    fol = fol & Range("F1").Text & "\"
    If Not fso.FolderExists(fol) Then
    fso.CreateFolder (fol)
    End If
    ActiveWorkbook.SaveAs Filename:=(fol & Range("A1").Value & ".XLS")
    ActiveWorkbook.Close
    'Call ClearCells
    Range("A1").Select
    Application.SendKeys ("%mb") '("%mb",[wait]) Wait Here!
    Application.SendKeys ("{ENTER}") '("%me",[1]) And Here!
    End Sub
    [/vba]

    Just can't get the syntax

    Many thanks

    Paul Ked
    Semper in excretia sumus; solum profundum variat.

  4. #4
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Paul

    What are you actually trying to use SendKeys to do?

  5. #5
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Remove the parentheses from the code. Use:
    [VBA]Application.Sendkeys "%fx", True[/VBA]
    rather than:
    [VBA]Application.Sendkeys("%fx", True)[/VBA]
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    That was just a sample before I saw your code - replace the key string with your own!
    Last edited by rory; 03-28-2008 at 10:26 AM.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Many thanks Rory, did the trick.
    Quote Originally Posted by Norie
    Paul

    What are you actually trying to use SendKeys to do?
    I have a package which communicates with vendors hardware and, unless I stop communications to the hardware, the system crashes when I try to save a file. This package is password protected and the easiest way to get round it is by using Sendkeys to stop communication and the restart it when file saved.

    Not the best solution, but an acceptable one

    Thanks again.

    Paul Ked
    Semper in excretia sumus; solum profundum variat.

  8. #8
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Rory, I deleted the odd extra posts that the board posted for you....I don't know what causes that.......
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Steve,
    Thanks - I thought it was my DT's kicking in...
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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