3

我正在处理我写的代码的插件 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
4

3 回答 3

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

于 2014-12-15T06:45:48.413 回答
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)

希望这会有所帮助。此致,

于 2014-12-14T18:44:48.527 回答
0

粘贴 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
于 2014-12-24T14:04:39.407 回答