ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel marco to screenshot a user form automatically? (https://www.excelbanter.com/excel-programming/382540-excel-marco-screenshot-user-form-automatically.html)

[email protected]

Excel marco to screenshot a user form automatically?
 
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!


Steve Yandl

Excel marco to screenshot a user form automatically?
 
The Word MVP web site has a short article on screen capture using VBA. The
top half uses SendKeys but below that is an example using API calls which is
what you will want to use.
http://word.mvps.org/FAQs/MacrosVBA/PrtSc.htm

Steve


wrote in message
ups.com...
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!




Tom Ogilvy

Excel marco to screenshot a user form automatically?
 
Modification of code originally posted by
"Orlando Magalhães Filho"

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

--
Regards,
Tom Ogilvy


wrote in message
ups.com...
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!




[email protected]

Excel marco to screenshot a user form automatically?
 
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


Tom Ogilvy

Excel marco to screenshot a user form automatically?
 
you are simulating Alt+PrintScreen

http://support.microsoft.com/default...b;en-us;153003

I think the best you can do is print the activewindow which in this case is
the userform.

--
Regards,
Tom Ogilvy

wrote in message
oups.com...
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





All times are GMT +1. The time now is 02:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com