Capture Screen Image via Code w/out User Interaction

  • Thread starter Thread starter dch3
  • Start date Start date
D

dch3

I'm entertaining the idea of enhancing my error logging by doing a screen
capture at the time that the error handler kicks in.

Anyone have experience with capturing the screen image and then saving it
via code?
 
Hi.

You can use a Windows API call to achieve this:

In the form's declaration section (i.e. at the top) enter:

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan
As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Then, in your error capture coding put:

keybd_event VK_SNAPSHOT, 1, 0, 0

This will copy a 'Print Screen' image to the clipboard. What will you to do
with that? Let me know and I'll try and help.

Cheers.

BW
 
From the clipboard, it'd be saving the image to a file. Off the top of the
head, mostly likely using Paint along the lines of Set objPaint =
CreateObject("Paint.Application"). Of course, I've never tried automating
paint and have no idea if its possible.
 
No, you can't automate Paint.

How about automating Word and pasting in the image.

Try:

Dim wdApp, docNew
keybd_event VK_SNAPSHOT, 1, 0, 0
Set wdApp = CreateObject("Word.Application")
With wdApp
docNew = .Documents.Add
.Selection.Paste
.Visible = True
End With

Cheers.

BW
 
Always a possibility, but if its an office app I'd probably end up looking
flat out at sending me messages via Outlook with the image. All of my
On_Error routines call an external sub which can be easily modified.
 
If your error log is a table, you could create a bound object frame field to
contain the picture, then set that field = the picture you copied to the
clipboard. I've never done this, but it seems like that would work. You can
imbed the picture into the field or the field can point to a file. Maybe I'm
off base with what you're trying to do.
 
Back
Top