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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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.
 
Upvote 0
Thanks for you're help. However, this only appears to copy a proportion of the Userform. The centre part.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,956
Messages
6,122,465
Members
449,085
Latest member
ExcelError

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
Back
Top