Consulting

Results 1 to 4 of 4

Thread: Excel 2013>VBA>Clipboard

  1. #1
    VBAX Regular
    Joined
    May 2016
    Posts
    73
    Location

    Excel 2013>VBA>Clipboard

    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!

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    What instruction is SendKeys? Also, have a look at PutInClipboard.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    May 2016
    Posts
    73
    Location
    Quote Originally Posted by mdmackillop View Post
    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!

  4. #4
    VBAX Regular
    Joined
    May 2016
    Posts
    73
    Location
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •