我想使用vba截图(然后将其作为电子邮件附件发送)。理想情况下,我想截取活动表单的截图。有没有办法做到这一点?有没有办法使用vba在MS-Access中截取屏幕截图?
回答
您必须使用Windows API调用来执行此操作。以下代码在MS Access 2007中可用。它将保存BMP文件。
Option Compare Database
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 Const VK_SNAPSHOT = &H2C
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Integer) As Long
Private Declare Function CloseClipboard Lib "user32"() As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" _
(PicDesc As uPicDesc, RefIID As GUID, ByVal fPictureOwnsHandle As Long, _
IPic As IPicture) As Long
'\\ Declare a UDT to store a GUID for the IPicture OLE Interface
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
'\\ Declare a UDT to store the bitmap information
Private Type uPicDesc
Size As Long
Type As Long
hPic As Long
hPal As Long
End Type
Private Const CF_BITMAP = 2
Private Const PICTYPE_BITMAP = 1
Sub PrintScreen()
keybd_event VK_SNAPSHOT, 1, 0, 0
End Sub
Public Sub MyPrintScreen(FilePathName As String)
Call PrintScreen
Dim IID_IDispatch As GUID
Dim uPicinfo As uPicDesc
Dim IPic As IPicture
Dim hPtr As Long
OpenClipboard 0
hPtr = GetClipboardData(CF_BITMAP)
CloseClipboard
'\\ Create the interface GUID for the picture
With IID_IDispatch
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With
'\\ Fill uPicInfo with necessary parts.
With uPicinfo
.Size = Len(uPicinfo) '\\ Length of structure.
.Type = PICTYPE_BITMAP '\\ Type of Picture
.hPic = hPtr '\\ Handle to image.
.hPal = 0 '\\ Handle to palette (if bitmap).
End With
'\\ Create the Range Picture Object
OleCreatePictureIndirect uPicinfo, IID_IDispatch, True, IPic
'\\ Save Picture Object
stdole.SavePicture IPic, FilePathName
End Sub
有一个Knowledge Base article进入更深入。
对不起,从死亡中提出这个,但这也适用于Access 2003?如果没有,我可以让它工作吗? – Magisch 2016-06-20 11:53:46
我刚刚通过代码..我不明白为什么它不会在Access 2003中工作,只要DLL存在。你有没有尝试过? – 2016-06-21 19:37:50
实现工程....大致。如果剪贴板内容实际上是一个打印屏幕,那里没有检查,但是直接调用它就好了。我现在留下的主要问题是,由此产生的图像文件很大......大约6mb用于全屏幕。从我看到的Access 2003中没有内置的方法将IPicture制作成.png并压缩它,你碰巧知道一个吗? – Magisch 2016-06-21 19:44:44
使用Raj的例子来获取图像,然后这个保存
Dim oPic
On Error Resume Next
Set oPic = Clipboard.GetData
On Error GoTo 0
If oPic Is Nothing Then
'no image in clipboard'
Else
SavePicture oPic, "c:\temp\pic.bmp"
end if
什么是PastePicture? – 2010-03-16 19:03:07
这是一个外部库,我编辑了我的原始文章 – bugtussle 2010-03-16 19:04:01
- 1. 如何在没有root的Android 2.3.3中截取屏幕截图?
- 2. 截取屏幕截图
- 3. C++截取屏幕截图
- 4. 有没有办法在界面构建器中截取整个ViewController的屏幕截图?
- 5. 有没有办法获得使用java锁定窗口的屏幕截图?
- 6. 有没有办法用White来拍摄整个屏幕的截图?
- 7. 在iOS 8中使用Objective C截取屏幕截图doesn'work
- 8. 使用HTML5/Canvas/JavaScript在浏览器中截取屏幕截图
- 9. 在C中使用selenium webdriver截取屏幕截图时的空白截图#
- 10. 无法在Android模拟器中截取屏幕截图
- 11. 屏幕截图
- 12. 使用c#截取屏幕截图使用c#
- 13. iOS:获取屏幕截图
- 14. ffmpeg获取屏幕截图
- 15. 如何在Windows应用程序中截取屏幕截图?
- 16. 如何在iPhone应用中截取屏幕截图?
- 17. 用C使用OpenGL截取屏幕截图#
- 18. 有没有办法通过URL自动截取网站的截图?
- 19. iPhone:屏幕截图
- 20. Webdriver屏幕截图
- 21. ASP.NET屏幕截图
- 22. C++屏幕截图
- 23. iPhone屏幕截图
- 24. Roku屏幕截图
- 25. 有没有办法检查截断表?
- 26. 截取应用程序中的屏幕截图
- 27. 有没有什么办法可以在IE上使用selenium RC来捕获整个页面的屏幕截图?
- 28. ffmpeg用于屏幕截图?
- 29. python中的屏幕截图
- 30. Haskell中的屏幕截图?
你需要这是全自动的吗?这就是为什么你不能使用Alt + PrintScreen? – 2010-03-16 18:23:19
是的,它必须是自动的。我想把它放在代码中,这样当用户执行特定操作时,就会截屏并通过电子邮件发送给管理员。 – dmr 2010-03-16 18:24:46
或者快照可以作为bmp保存到错误消息表中。以及其他信息,如活动表格名称,工作站号码,用户ID,日期/时间等。 – 2010-03-17 00:39:49