Gricks
Gricks

Reputation: 43

Excel 2010 VBA Code to copy screen to clipboard

I am looking for VBA code in Excel 2010 that will allow me to take a screen shot of a specific range in Excel.

Right now, when I select a range in excel, then copy, the view is distorted from the actual screen view.

Let me know if you have any questions - thanks.

Upvotes: 0

Views: 5341

Answers (1)

Gricks
Gricks

Reputation: 43

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

This link worked perfectly for what I needed.

The entire code for 64 bit is below:

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

Upvotes: 1

Related Questions