Excel marco to screenshot a user form automatically?

  • Thread starter Thread starter Shaka215
  • Start date Start date
S

Shaka215

Hello,

I am wondering if it is possible to have Excel take a screen shot
of a userform as soon as it loads without using the SendKeys...the
reason being I'd like to be able to archive the results (graphically)
when a end-user presses a button. Any ideas? Your help is greatly
appreciated!
 
Modification of code originally posted by
"Orlando Magalhães Filho" <[email protected]>

Modified to capture just the userform (not the whole window).

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

Public Const VK_SNAPSHOT = 44
Public Const VK_LMENU = 164
Public Const KEYEVENTF_KEYUP = 2
Public Const KEYEVENTF_EXTENDEDKEY = 1


Sub Test()
UserForm1.Show
End Sub


In the userform module:




Private Sub CommandButton1_Click()
' keybd_event VK_SNAPSHOT, 0, 0, 0
DoEvents
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0 ' key down
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
DoEvents
Workbooks.Add
Application.Wait Now + TimeValue("00:00:01")
ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False,
DisplayAsIcon:=False
ActiveSheet.Range("A1").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWorkbook.Close False
End Sub
 
Tom,


Can you please inform me of where/how you managed to get it just to
snap the userform instead of the entire screen? I tried scanning
through the code to figure it out but I didn't see it anywhere...maybe
is it possible to just snap a FRAME of a userform with this code
instead of the entire window? Thanks alot man and to everyone else who
helped!

-Todd
 
Back
Top