【问题标题】:Invoke a Sub when I press a key in vba powerpoint当我在 vba powerpoint 中按下一个键时调用一个 Sub
【发布时间】:2015-02-15 20:26:23
【问题描述】:

此代码通过调用sub PrintScreen获取要粘贴的数字屏幕截图并将其粘贴到power point幻灯片中,然后需要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

这是我的打印屏幕子。

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

【问题讨论】:

    标签: vba keyboard-shortcuts powerpoint


    【解决方案1】:

    由于缺少功能,powerpoint 不支持 onkey。 因此,尝试用 C++ 编写代码并为其分配键,然后 shell 执行您的代码,就像在您的情况下将 F7 分配给 ALT+PrintScrn即,当您按 F7 时,它应该截取当前窗口的屏幕截图。 这是shell执行的代码

    Sub PrintScreen()
    Dim sFullPathToExecutable As String
    sFullPathToExecutable = "C:\Users\abc.exe"
    Shell sFullPathToExecutable
    End Sub
    

    【讨论】:

    • 我们如何在 Word 中做到这一点?我有同样的问题陈述。我想运行一个子程序,除非停止,否则它将继续运行,它会在观察到打印屏幕被按下时调用另一个子程序,并在 word doc 中获取该捕获。你能建议怎么做吗?
    【解决方案2】:

    PowerPoint 不支持将键盘快捷键分配给宏 like in 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 为您的宏分配的数字快捷方式。

    【讨论】:

    • 我想要这样的代码,任何像 key 这样的键都是 Alt(Keybd_event VK_MENU, 0 , 0, 0) 如果键被按下然后转到 sub else donothing 或类似的事情 If thekey= true Then goto sub Else donothing 我知道我们可以通过 OnKey 方法在 excel 中执行此操作,但我在 powepoint 中遇到问题。
    猜你喜欢
    • 1970-01-01
    • 2016-10-24
    • 2018-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    相关资源
    最近更新 更多