PDA

View Full Version : [SOLVED] Excel 2013>VBA>Clipboard



aworthey
07-07-2016, 09:21 AM
I am capturing a screenshot of a userform and pasting it into a temp worksheet to create a PDF. The code is working as I expect it to except for one aspect: it seems to paste first before saving new image to clipboard. That is to say, that each paste event is from previous screen capture. It seems it's a sequence of events problem, but I've not been able to figure it out.

Here's the code:


Dim shape As Excel.shape


For Each shape In ThisWorkbook.Worksheets("temp").Shapes
shape.Delete
Next


ThisWorkbook.Application.SendKeys "(%{1068})"
DoEvents

ThisWorkbook.Worksheets("temp").Paste
DoEvents


The first few lines clears my worksheet before pasting.

Thanks!

mdmackillop
07-07-2016, 09:30 AM
What instruction is SendKeys? Also, have a look at PutInClipboard.

aworthey
07-07-2016, 10:01 AM
What instruction is SendKeys? Also, have a look at PutInClipboard.

I understand SendKeys to allow user to "press" keyboard keys through VBA. So, SendKeys "(%{1068})" allows me to take a screenshot of my userform to paste it in a temp worksheet.

How would I use PutInClipboard with my screenshot?

I appreciate your response!

aworthey
07-07-2016, 11:26 AM
Here's the fix:


Excel.Application.Wait (Now + TimeValue("0:00:01"))

I inserted this 1 second delay between the screen capture and paste to give it enough time to save on clipboard.