0
votes

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.

1
Are you looking for someone to do it for you? What have you tried?ChiefTwoPencils
What exactly does "the view is distorted" mean? When you copy from Excel to the clipboard, you don't get an image; you get plain text, Unicode text, etc., but you don't get a graphic. What exactly are you trying to do with the range you're copying afterward? I really doubt a screen capture is the best way to achieve it.Ken White
Ken - view is distorted when I do a copy of the range - then paste into paint as an image. So I am trying to find the VBA to get a screen shot of the range - does that make sense?Gricks
Roberto - I have tried doing a copy of the range - then pasting into paint as an image - it comes back distorted - so I am looking for VBA in Excel 2010 that will take a screen shot of the range - not copy and paste itGricks

1 Answers

1
votes

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