Excel 2010 VBA代码将屏幕复制到剪贴板

时间:2012-08-11 20:32:43

标签: excel-vba vba excel

我在Excel 2010中寻找VBA代码,这样我就可以在Excel中拍摄特定范围的屏幕截图。

现在,当我在Excel中选择一个范围,然后复制时,视图会从实际的屏幕视图中失真。

如果您有任何问题,请与我联系 - 谢谢。

1 个答案:

答案 0 :(得分:1)

http://support.microsoft.com/kb/240653

此链接完全符合我的需要。

64位的整个代码如下:

Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Declare PtrSafe Function GetVersionExA Lib "kernel32" _
(lpVersionInformation As OSVERSIONINFO) As Integer


Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12

Dim blnAboveVer4 As Boolean

Sub takeScreenShot()

   If blnAboveVer4 Then
     keybd_event VK_SNAPSHOT, 0, 0, 0
   Else
     keybd_event VK_SNAPSHOT, 1, 0, 0
   End If
End Sub