|
OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy |
| Timed application display and termination |
|
|
Copy the code below into a code module and set a shape to run the macro - TimedAppDisplay. Start the slide show and click on the shape to execute the macro. It will launch the notepad application and then after 7 seconds it will automatically terminate the application and resume the slide show. |
|
|
' --------------------------------------------------------------------------------
Option Explicit
End Type
End Type Const SYNCHRONIZE = 1048576 Const NORMAL_PRIORITY_CLASS = &H20& Const EXE_PATH_AND_NAME = "Notepad.exe"
Const APP_NAME = "Timed Application
Display" Sub TimedAppDisplay() Dim strucProcInfo As PROCESS_INFORMATION Dim strucStartInfo As STARTUPINFO Dim sNull As String Dim lSuccess As Long
Dim lRetValue As Long
On Error GoTo HandleErr lSuccess = CreateProcess(sNull, EXE_PATH_AND_NAME, ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, _
Sleep 7000 'Sleep for 7 seconds lRetValue = TerminateProcess(strucProcInfo.hProcess, 0&) lRetValue = CloseHandle(strucProcInfo.hThread) lRetValue = CloseHandle(strucProcInfo.hProcess) DoEvents ' Force the slide show window to the front Call SetForegroundWindow(FindWindow("screenClass", 0&)) ExitHere:
Exit Sub Select Case Err.Number Case Else MsgBox "Error " & Err.Number & ": " & Err.Description, _ vbCritical, APP_NAME & " " & "TimedAppDisplay" End Select
End Sub |
|
Copyright 1999-2018 (c) Shyam Pillai. All rights reserved.