Ctrl+Printscreen via VBA

Coley

New Member
Joined
Sep 25, 2006
Messages
5
I have this code taken from a previous post which works perfectly.

Code:
Option Explicit

Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const VK_SNAPSHOT = &H2C

Sub PrintScreen()
keybd_event VK_SNAPSHOT, 0, 0, 0
End Sub

What i would really like, is to amend this so it only copies the Dialog boxes that are open (usually Keystroke Ctrl+PrintScreen).

Help would be appreciated
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

BJungheim

Well-known Member
Joined
Jul 24, 2004
Messages
914
This appears to work:
Code:
Option Explicit

Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const VK_SNAPSHOT = &H2C

Sub PrintScreen()
keybd_event VK_SNAPSHOT, 1, 0, 0
End Sub

Note the value of bVk in the Sub.
 

Coley

New Member
Joined
Sep 25, 2006
Messages
5
Thanks for you're help. However, this only appears to copy a proportion of the Userform. The centre part.
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,939
Office Version
  1. 2016
Platform
  1. Windows
Here is a demo that copies the Data Validation Dialoge Box...See if it works .

Code:
'\this is a routine to show how
'\to copy the DataValidation Dialog box
'\to the Clipboard. can be adapted to
'\copy any other dialog or active child window

Option Explicit

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

Private Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long

Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long

Dim lTimerID As Long

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


Private Sub TimerProc()
 
    '\we don't need the timer anymore
    KillTimer 0, lTimerID
    '\ press the ALT key
    keybd_event VK_MENU, 0, 0, 0
    '\ press the PrtSc key
    keybd_event VK_SNAPSHOT, 0, 0, 0
    '\ release the PrtSc key
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
    '\ release the ALT key
    keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0

End Sub


'run this test routine

Sub Copy_DataValidation_DialogBox()

    lTimerID = SetTimer(0, 0, 100, AddressOf TimerProc)
    Application.Dialogs(xlDialogDataValidation).Show

End Sub

Regards.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,537
Messages
5,529,426
Members
409,876
Latest member
Akash Yadav
Top