Bring external application to the foreground using Excel VBA

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:

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?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top