• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Not able to get screenshot of active workbook

ThrottleWorks

Excel Ninja
Hi,
I am trying to get screenshot of active worksheet.
Below code is written in this workbook.
Before calling this module, another workbook is opened.

When I run this code by doing F5, I get screenshot of ThisWorkbook and not activeworkbook.

If I run code by doing F8, I get screen of code window.
How do I get screenshot of activeworksheet.

Can anyone please help me in this.
Also, when I run this code, NUMLOCK gets off. Do not know why.

Code:
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
Sub PrintScreen()
    Application.SendKeys "({1068})", True
    DoEvents
    ActiveSheet.Paste
End Sub
 
Hmm, code works fine on my end, but you don't need Private parts.
Code:
Option Explicit
Sub CopyScreen()

Application.SendKeys "({1068})", True
DoEvents
ActiveSheet.Paste

End Sub
In my setup this code will take snapshot of both monitors in dual monitor setup

How are you running the code? (I ran it using VBE, while having another workbook in the fore)
 
Back
Top