gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:49:23 26 4
gpt4 key购买 nike

我正在处理加载项 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

最佳答案

您的帖子实际上包含下面回答的 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)

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

关于vba - 如何使用 PowerPoint VBA 自动执行延迟屏幕捕获/粘贴过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27472558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com