当我按VBA Powerpoint中的一个键时调用一个Sub [英] Invoke a Sub when I press a key in vba powerpoint
问题描述
此代码捕获活动窗口,并通过调用 sub PrintScreen
来粘贴要粘贴的数字屏幕截图,然后将其粘贴到Powerpoint幻灯片,此后需要5秒钟来捕获活动窗口的屏幕.虽然我希望每当我按下诸如"F7或F3等"之类的特定键时,它都应该显示屏幕,而不是等待5秒钟.我只想按该键,它将调用在其中指定打印和粘贴以及其他功能的子程序.
This code captures the active window and paste it to power point slides by taking number screenshots to be pasted, by calling a sub PrintScreen
, After that it takes 5 seconds to capture screen of active window. While i want that whenever i press a specific key like 'F7 or F3 etc' it should take print screen instead of waiting 5 seconds. I just want to press the key and it invokes sub in which i specify the print and paste and other functions.
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
推荐答案
由于缺少功能,powerpoint不支持onkey.因此,请尝试在 C ++ 中编写代码并为其分配键,然后shell执行您的代码,例如在您的情况下,将 F7 分配给 ALT + PrintScrn 即,当您按F7键时,应该获取当前窗口的屏幕截图.这是shell执行的代码
Due to lack of features powerpoint doesnot support onkey. So try to write a code in C++ and assign keys to it and shell execute your code, like in your case assign F7 to ALT+PrintScrn i.e when you press F7 it should take screenshot of your current window. Here is the code for shell execution
Sub PrintScreen()
Dim sFullPathToExecutable As String
sFullPathToExecutable = "C:\Users\abc.exe"
Shell sFullPathToExecutable
End Sub
这篇关于当我按VBA Powerpoint中的一个键时调用一个Sub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!