如何使用PowerPoint VBA自动延迟屏幕捕获/粘贴过程?

时间:2014-12-14 18:29:20

标签: screenshot wait copy-paste powerpoint-vba powerpoint-2010

我正在处理插件powerpoint我编写的代码正在打印屏幕并将其复制到剪贴板。虽然我希望这个复制的图像粘贴在我的powerpoint幻灯片中。另外我面临的另一个问题是,每当我点击“运行”时,它会立即将图像复制到剪贴板,而我想要添加计时器,当我点击“运行”时,它会在5秒后打印出屏幕。以下是代码。

    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

3 个答案:

答案 0 :(得分:1)

您的帖子实际上包含以下2个问题;

1)。为了将捕获的屏幕截图图像从剪贴板内存粘贴到PowerPoint幻灯片(例如添加第一张空白幻灯片),请使用以下语句:

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

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

中详细了解此主题

2)。要添加5秒延迟,请使用在感兴趣的宏中插入的以下语句:

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

或者,您可以使用Sleep(5000)函数,但需要声明:

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

希望这会有所帮助。最好的问候,

答案 1 :(得分:1)

这会捕获打印屏幕并将其粘贴到幻灯片中。

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

答案 2 :(得分:0)

在粘贴表现时应该存在线间隙

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