vbapowerpointscreenshotcopy-pastepowerpoint-2010

How to automate delayed screen capture/paste procedure using PowerPoint VBA?


I am working on add-in powerpoint the code i had written is taking print screen and copy it to clip board. While i want this copied image to pasted in my powerpoint slide. Also another I am facing is that whenever i click on 'Run' it copy image to clip board without any delay while i want to add timer that it take print screen after 5 seconds when i click 'Run'. The following is the code.

    Option Explicit

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

Private Declare Function GetVersionExA Lib "kernel32" _
      (lpVersionInformation As OSVERSIONINFO) As Integer

Private Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type

Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12

Dim blnAboveVer4 As Boolean

Private Sub Command1_Click()
    If blnAboveVer4 Then
        keybd_event VK_SNAPSHOT, 0, 0, 0
    Else
        keybd_event VK_SNAPSHOT, 1, 0, 0
    End If
End Sub

Private Sub Command2_Click()
    If blnAboveVer4 Then
        keybd_event VK_SNAPSHOT, 1, 0, 0
    Else
        keybd_event VK_MENU, 0, 0, 0
        keybd_event VK_SNAPSHOT, 0, 0, 0
        keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
        keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
    End If
End Sub

Solution

  • There should be a line gap while pasting acivepresentation

    Sub PrintScreen()
        keybd_event VK_MENU, 0, 0, 0
        keybd_event VK_SNAPSHOT, 0, 0, 0
        keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 
        keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
    
        ActivePresentation.Slides.Add 1, ppLayoutBlank
        ActivePresentation.Slides(1).Shapes.Paste
    
    End Sub