VBA code to take a screenshot of a userform

seleseped

Board Regular
Joined
Feb 1, 2005
Messages
59
Hello,
I would like a command button which would copy a 'completed' userform and save it to a clipboard for pasting into a Microsoft Word document as a permanent record of the data entered into the form. I've tried the following code . . .

Private Sub cmdCopy_Click()
UserForm1.Copy

End Sub

. . . but get a message from Word that there's a problem saving the file ("There is a problem saving the file. Usually this is because the disk or floppy disk is too small for the file or is full, RAM memory is low, or there is a permission problem with the drive the file is being saved to. If the amount of disk space for a paging file is low, save the file to another drive. If the RAM memory is low, increase available RAM. If permissions to the drive do not allow you to save to that drive, save the file to another drive or request permissions from the administrator to save files to the drive.").

As a work-around, a copied screenshot of the completed userform would also suit my purpose. Does anybody know of any VBA code which would accomplish this (that is, take a screenshot of the form, save it to a clipboard, and make the screenshot available to Word)?

Many thanks in advance for your time and expertise.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Here you go it use sendkey method as sendkey can disable the numeric lock, in that case just uncomment the 2nd line of code.


Put it inside at end of commandbutton that is used to close/finish your userform or you can put it on userform unload

Code:
Application.SendKeys "(%{1068})"
'Application.SendKeys "{NUMLock}", True  'un comment this if numeric lock key get disabled
DoEvents
 
Upvote 0
This solution works like a charm! Many thanks. (As an aside, the NumLock key does indeed get disabled; uncommenting the second line of code nicely solves that problem.)


Here you go. It uses the sendkey method. Sendkey can disable the numeric lock; in that case just uncomment the 2nd line of code.

Put the code inside at end of the command button that is used to close/finish your userform or you can put it on userform unload.

Code:
Application.SendKeys "(%{1068})"
'Application.SendKeys "{NUMLock}", True  'uncomment this if numeric lock key gets disabled
DoEvents
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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