在vba powerpoint中按键时调用Sub

Ali*_*lik 2 vba keyboard-shortcuts powerpoint-vba

此代码捕获活动窗口并将其粘贴到功率点幻灯片上,方法是通过调用a来粘贴数字屏幕截图sub PrintScreen,之后需要5秒钟来捕获活动窗口的屏幕.虽然我希望每当我按下像'F7或F3等'的特定键时,它应该采用打印屏幕而不是等待5秒钟.我只想按下键并调用sub,其中我指定了打印和粘贴以及其他功能.

Sub Screen_Capture_VBA()
 Dim Sec4 As Date
 MsgBox "Note: Three seconds after you click OK " & _
 "the active window will be copied to the clipboard."
 Sec4 = DateAdd("s", 4, Now)
 myValue = InputBox("Give me no of screen shots you want to capture")
 For I = 1 To myValue
 PrintScreen
 Next I
End Sub
Run Code Online (Sandbox Code Playgroud)

这是我的打印屏幕子.

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
Run Code Online (Sandbox Code Playgroud)

And*_*ohr 7

PowerPoint不支持为Excel中的宏指定键盘快捷键.您可以购买第三方应用程序,如OfficeOne Shortcut Manager,但更简单的解决方法是将宏添加到快速访问工具栏.

  1. 单击QAT下拉箭头(下方突出显示为黄色)
  2. 点击 More Commands
  3. 在下拉列表中Choose commands from选择
  4. 单击YourPresentationName!PrintScreen
  5. 单击Add >>按钮
  6. 点击 OK

在此输入图像描述

然后你可以使用alt+ 1(或QAT指定的任何数字)来执行PrintScreen().按alt一次键,查看PowerPoint分配给宏的快捷方式号码.

在此输入图像描述

  • 我想要这样的代码 任何像 thekey 这样的键是 **Alt(Keybd_event VK_MENU, 0 , 0, 0)<--它被按下** 如果按下了该键,则转到 sub else donothing 或类似的东西 If thekey= true Then goto sub Else donothing 我知道我们可以通过 OnKey 方法在 excel 中做到这一点,但我在 powepoint 中遇到了问题。 (2认同)