Martin1979
New Member
- Joined
- Mar 29, 2013
- Messages
- 9
Hi all,
I am struggling with a piece of code which allows me to bring an external application screen to the foreground and perform some sendkeys instructions on it. Can anyone help me with this?
The code I have so far is:
How do I incorporate something which brings the 'CurveMeasurement.exe' application to the foreground and perform the sendkeys instructions on it?
I am struggling with a piece of code which allows me to bring an external application screen to the foreground and perform some sendkeys instructions on it. Can anyone help me with this?
The code I have so far is:
Code:
Sub WRun()
Dim strTerminateThis As String
Dim vFileName
Dim cntFiles()
Dim cntF As Integer
Dim curF As Integer
Application.CutCopyMode = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
cntF = 0
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select a folder"
If .Show = -1 Then
sFolder = .SelectedItems(1) & "\"
Else
Exit Sub
End If
End With
myExtension = "*.dim"
myFile = Dir(sFolder & myExtension)
Do While myFile <> ""
ReDim Preserve cntFiles(cntF)
cntFiles(cntF) = sFolder & myFile
cntF = cntF + 1
myFile = Dir
Loop
strTerminateThis = "CurveMeasurement.exe" 'shell program
aVal = 23 'hours to wait until process is completed
For curF = 0 To cntF - 1
Set objWMIcimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objList = objWMIcimv2.ExecQuery("select * from win32_process where name='" & strTerminateThis & "'")
For Each objProcess In objList
intError = objProcess.Terminate
If intError <> 0 Then Exit For
Next
Set objWMIcimv2 = Nothing
Set objList = Nothing
Set objProcess = Nothing
myFile = cntFiles(curF)
CreateObject("Shell.Application").Open (myFile) 'opens *.dim files in CurveMeasurement.exe
Application.Wait Now + TimeValue("00:00:05")
Application.SendKeys ("{F10}")
Application.Wait Now + TimeValue("00:00:05")
Application.SendKeys ("{ENTER}")
Application.Wait Now + TimeValue("00:00:05")
Application.SendKeys ("{ENTER}")
Application.Wait DateAdd("h", aVal, Now)
Application.SendKeys ("^(s)")
Application.Wait Now + TimeValue("00:02:00")
Next curF
End Sub
How do I incorporate something which brings the 'CurveMeasurement.exe' application to the foreground and perform the sendkeys instructions on it?