View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Can Excel capture a screenshot?

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


"Albert" wrote in message
...
Hello!
Is it possible to have Excel capture a screenshot with the ontime
procedure?
I'd like to have Excel and another application running simultaneously and
have Excel capture a screenshot every 5 minutes and paste it in the
current
sheet.
Bonus: is it possible to capture a screenshot Only of the other
application?
I thank you in advance,
Albert C.