automate alt+printscreen and paste to powerpoint slide

J

Jennifer

I know to capture the current screen into the clipboard you have to
press alt + printscreen. Then press ctrl + v to paste it to PPT. I've
written code in VBA to automate this process. Only I get errors when
the computer tries to either 1)press alt + printscreen and 2)press
ctrl + v (or paste function). Does anyone know of a solution to this?
The two lines of code are as follows:
1)keybd_event vbKeySnapshot, 1, 0, 0
2)powerpoint.ActiveWindow.View.Paste

Any help or advice or links to websites is helpful!
 
S

Shyam Pillai

Jennifer,
This snippet copies the active window to the clipboard and pastes the image
to a PowerPoint slide.
--
' ----- Beginning Of Code -----
Option Explicit
Public Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)

Const TheScreen = 0
Const TheForm = 1

Sub CaptureActiveFormImageToSlide()
On Error GoTo ErrHandler
Dim oCaptureOutput As Presentation
Dim oSld As Slide

keybd_event vbKeySnapshot, TheForm, 0&, 0&

DoEvents
'Add a new presentation
Set oCaptureOutput = Presentations.Add(False)
With oCaptureOutput
' Insert blank slide
Set oSld = .Slides.Add(.Slides.Count + 1, ppLayoutBlank)
' Paste image
Call oSld.Shapes.Paste(1)
End With
'Show the PPT file
oCaptureOutput.NewWindow
Set oCaptureOutput = Nothing
' Add code to clear the clipboard here

Exit Sub
ErrHandler:
MsgBox Err.Description, vbCritical, Err.Number
End Sub

' ----- End Of Code -----
--
Regards
Shyam Pillai

Handout Wizard
http://www.mvps.org/skp/how/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top