PDA

View Full Version : Solved: Sendkeys using wait.



paulked
03-28-2008, 06:17 AM
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: =) :banghead:

Any ideas?

Best regards

Paul Ked

lucas
03-28-2008, 07:49 AM
Hi Paul,
Show us the code you are having trouble with please.

paulked
03-28-2008, 08:35 AM
Hi Paul,
Show us the code you are having trouble with please.

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


Just can't get the syntax :think:

Many thanks

Paul Ked

Norie
03-28-2008, 08:38 AM
Paul

What are you actually trying to use SendKeys to do?

rory
03-28-2008, 08:40 AM
Remove the parentheses from the code. Use:
Application.Sendkeys "%fx", True
rather than:
Application.Sendkeys("%fx", True)

rory
03-28-2008, 08:42 AM
That was just a sample before I saw your code - replace the key string with your own!

paulked
03-28-2008, 09:53 AM
Many thanks Rory, did the trick.

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 :whistle:

Thanks again.

Paul Ked

lucas
03-28-2008, 10:12 AM
Rory, I deleted the odd extra posts that the board posted for you....I don't know what causes that.......

rory
03-28-2008, 10:25 AM
Steve,
Thanks - I thought it was my DT's kicking in... :)