作者:绿色风
分类:
时间:2022-08-18
浏览:268
楼主 xmyjk |
Q:如何运用VBA进行工作表截图? 分两种需求:一种截取EXCEL窗口屏幕的内容,第二种截取工作表USEDRANGE的内容
A:一、截取EXCEL窗口屏幕内容:采用模拟键盘按键ALT+PRTSC进行操作:- Option Explicit
- Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
- Private Const VK_KEYUP = &H2
- Private Const VK_SNAPSHOT = &H2C
- Private Const VK_MENU = &H12
- Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
- Private Const SW_MAXIMIZE = 3
- Private Const SW_SHOWNORMAL = 1
- Private Const SW_SHOWMINIMIZED = 2
- Sub Print_Screen()
- Dim SH As Worksheet
-
- Set SH = ActiveSheet
-
- keybd_event VK_MENU, 0, 0, 0
- DoEvents
- keybd_event VK_SNAPSHOT, 0, 0, 0
- DoEvents
- keybd_event VK_SNAPSHOT, 0, VK_KEYUP, 0
- DoEvents
- keybd_event VK_MENU, 0, VK_KEYUP, 0
- DoEvents
-
- SH.Range("A1").Select
- SH.Paste
- End Sub
123ok1.rar
第二个:制作USDRANGE内容的图片并保存,运用CopyPicture+操纵剪贴板+EnhMetaFileA(创建位图元素保存)- Option Explicit
- Private Declare Function OpenClipboard Lib "User32" (ByVal hWnd As Long) As Long
- Private Declare Function CloseClipboard Lib "User32" () As Long
- Private Declare Function GetClipboardData Lib "User32" (ByVal uFormat As Long) As Long
- Private Declare Function CopyEnhMetaFileA Lib "Gdi32" (ByVal hemfSrc As Long, ByVal lpszFile As String) As Long
- Private Declare Function DeleteEnhMetaFile Lib "Gdi32" (ByVal hdc As Long) As Long
- Sub test()
- Dim picnm As String
- picnm = Application.GetSaveAsFilename("try1.jpg", "图片, *.jpg", , "请选择保存路径并键入文件名")
- ActiveSheet.UsedRange.CopyPicture
- OpenClipboard 0
- DeleteEnhMetaFile CopyEnhMetaFileA(GetClipboardData(14), picnm)
- CloseClipboard
- Range("a1").Select
- ActiveSheet.Paste
- End Sub
xxxx.rar
该帖已经同步到 |
2楼 简单一点 |
不知道10里面的 插入-屏幕截图-屏幕剪辑 的方法应该怎么调用? |
3楼 JOYARK1958 |
謝謝提供學習下載中 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一