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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

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
8,311
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.
 

Forum statistics

Threads
1,141,740
Messages
5,708,233
Members
421,553
Latest member
Geeyj

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top