Your question is rather vague, what application, will it be visible and the
be active-window, if so how to be sure, or maybe it has a handle, etc etc.
Try the following, after running StartCapture activate the window of your
application within 10 seconds
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_SNAPSHOT As Long = 44&
Private Const VK_LMENU As Long = 164&
Private Const KEYEVENTF_KEYUP As Long = 2&
Private Const KEYEVENTF_EXTENDEDKEY As Long = 1&
Dim mNextOnTime As Date
Sub StartCapture()
mNextOnTime = Now + TimeSerial(0, 0, 10) ' 10 seconds for testing
Application.OnTime mNextOnTime, "Capture"
End Sub
Sub StopCapture()
' cancel the ontime, eg call from the wb's close event
If mNextOnTime Then
Application.OnTime mNextOnTime, "Capture", , False
End If
End Sub
Sub Capture()
Dim tlRow As Long, brRow As Long
Dim shp As Shape
' like SendKeys Alt-PrtScn
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
DoEvents
For Each shp In ActiveSheet.Shapes
brRow = shp.BottomRightCell.Row
If brRow > tlRow Then tlRow = brRow
Next
Cells(tlRow + 1, 2).Activate
ActiveSheet.Paste
ActiveCell.Activate
AppActivate Application.Caption
If MsgBox("Capture again in 10 seconds", vbYesNo) = vbYes Then
StartCapture
End If
End Sub
Regards,
Peter T