3

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
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Ajmal Jamil
  • 799
  • 1
  • 8
  • 15

3 Answers3

2

Your post actually contains 2 questions answered below;

1). In order to paste the captured screenshot image from the clipboard memory to PowerPoint Slide (for e.g. added 1st blank slide ) use the following statement:

ActivePresentation.Slides.Add 1, ppLayoutBlank
ActivePresentation.Slides(1).Shapes.Paste

Read more on this topic in https://social.msdn.microsoft.com/Forums/en-US/006bdb95-1889-4a3a-8eb9-fc7b2af88805/paste-a-picture-from-clipboard-to-slide-how-c

2). In order to add a 5sec delay, use the following statement inserted in the macro of interest:

Application.Wait(Now + TimeValue("00:00:05"))

Alternatively, you can use Sleep(5000) function, but it will require declaration:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Hope this will help. Best regards,

Alexander Bell
  • 7,842
  • 3
  • 26
  • 42
  • Application.Wait isn't available in the PPT object model, but a call to Sleep works fine. – Steve Rindsberg Dec 14 '14 at 21:24
  • 1
    I have rewrite the code, it copy image from clip board to ppt slides but the sleep call is not working properly, following is the code. **Sub PrintScreen() Sleep (5000) 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 ActivePresentation.Slides.Add 1, ppLayoutBlank ActivePresentation.Slides(1).Shapes.Paste End Sub** – Ajmal Jamil Dec 14 '14 at 21:41
  • 1
    Actually i want to go to other window during these 5 seconds and want to capture that screenshot i.e. want to take print screen after 5 seconds whatever the window is open or maximize at that time(browser or ppt or folder). – Ajmal Jamil Dec 14 '14 at 21:51
  • You are welcome! Please mark the question answered. If you have more questions, please put them in a separate post. Best regards, – Alexander Bell Dec 15 '14 at 00:33
  • 1
    There is some additional info on PasteSpecial in case you may need it for any future development: http://office.microsoft.com/en-001/powerpoint-help/paste-special-HP010117115.aspx. Good luck with your project. Best regards, – Alexander Bell Dec 15 '14 at 14:13
1

This captures the print screen and paste it to slide.

Sub PrintScreen() 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 ActivePresentation.Slides.Add 1, ppLayoutBlank ActivePresentation.Slides(1).Shapes.Paste End Sub

Ajmal Jamil
  • 799
  • 1
  • 8
  • 15
0

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
Ali Malik
  • 82
  • 1
  • 1
  • 8