Closed Thread
Results 1 to 19 of 19

Add Clipboard Image to UserForm

  1. #1
    Registered User
    Join Date
    03-08-2017
    Location
    Durban, South Africa
    MS-Off Ver
    2010
    Posts
    8

    Add Clipboard Image to UserForm

    Hi,

    I have seen this posted a few times, but none of the responses I have seen are able to answer my question.
    I have a table in a Sheet which contains monitoring data for boreholes, the format of the table is very specific and the color of the cells and text is important for interpretation of the data.

    I would like to write a script whereby clicking a button will open a form which then presents the table - as is - within the boundaries of the form.
    I am using Excel 2010, so the Spreadsheet control is no longer around, and I can do the process manually by using the picture control and setting the source to "(metafile)" or copying the spreadsheet as a picture and pasting it into the properties of the picture control.

    I know there is a workaround in getting the Spreadsheet Control via a download, but if I want to distribute my Workbook the user will need to have this installed too, which is not an option for me.

    Is there something I can script to accomplish this?
    On top of that, is there a way then to automate the form so that the width and height of the form changes based on the table width and height? The data is dynamic, so I would prefer to not have to re-work the script everytime the monitoring data is returned.

    Any thoughts / suggestions are welcomed.

    K

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Add Clipboard Image to UserForm

    Hi,

    You can use Stephen Bullen's well known Paste Picture code. Add this to a new module
    Please Login or Register  to view this content.
    then all you need is a userform with an Image control and some code like this
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    03-08-2017
    Location
    Durban, South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: Add Clipboard Image to UserForm

    Wow thank you.
    I guess I wasnt searching in the right areas.

    I will try and implement this and let you know if I got it to work.

    Thank you!

  4. #4
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Add Clipboard Image to UserForm

    I tried something similar to the above code, but it crashed for me... Another technique I found was to use the chart object, which worked ok. Try this in a User Form module with a image called 'Image1' on it. (Tried to attach workbook, but no luck...)

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-08-2017
    Location
    Durban, South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: Add Clipboard Image to UserForm

    Thank you all!

    I will test these out now.
    I am trying to avoid writing to a directory, as I am unsure where this will be run from (if that makes sense)

    Using the Clipboard will avoid potential errors if the user has a drive different to the drive I specify as the "bitmap" save location.

  6. #6
    Registered User
    Join Date
    03-08-2017
    Location
    Durban, South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: Add Clipboard Image to UserForm

    I thought I recognised this.
    I downloaded the XLS from the OALTD website last week, I have the same error with regards to having to update it to 64 bit.
    I will google how to do this, because it is now the second time I have seen it posted as an option to do what I need it to.

    Ok...done...here is the final code....thank you all that assisted...xlnitwit your idea is what used.

    In a new module:

    Please Login or Register  to view this content.
    Then in the new form I added this code, with a Picture Control:

    Please Login or Register  to view this content.
    A summary of changes:

    1) Added PtrSafe to all the Declares
    2) Changed "olepro32.dll" to "oleautpro.dll"
    3) Changed how it selects and copies the table.

    Hopefully this will help someone in future.

    Thanks again for all the help!

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Add Clipboard Image to UserForm

    FYI, that code is not properly updated for 64bit Office. You are missing several changes of Long to LongPtr.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Add Clipboard Image to UserForm

    To work with either you would require something like this- attached as the code seems to be too long to paste inline.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    03-08-2017
    Location
    Durban, South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: Add Clipboard Image to UserForm

    Cool thanks.

    I seemed to have made those changes too

    Posted it in the code above in case anyone needed it.
    I missed the LongPtr, but the code seems to work without it.

    I think your code is great, it lets the user be 32 or 64 bit, thank you for posting that!
    I will definitely implement it, I appreciate the time you have taken to share this input.
    Last edited by Keags; 03-08-2017 at 09:52 AM. Reason: spelling

  10. #10
    Registered User
    Join Date
    03-08-2017
    Location
    Durban, South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: Add Clipboard Image to UserForm

    I know I placed this as "Solved" but I was hoping I might get some clarity on an error which is creeping in randomly.

    I have set the code to run when "buttons" are clicked in Sheet1 of my work book.
    Depending on the button clicked (which refer to sampling points) the sheet with the related data (held in separate sheets) is then copied into the form.

    The code works 100%, 80% of the time.

    It is a bit random, but after 6, 10 or 12 clicks, I receive a 1004 Error stating that the "CreatePicture" is out of range.
    If i simply select debug and complete the script, it still works 100%.

    Then, after 6 to 12 clicks it happens again.

    I have tried clicking quickly, I have tried clicking slowly and I get the same error and the same results.

    Any thoughts?
    Last edited by Keags; 03-09-2017 at 09:05 AM.

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Add Clipboard Image to UserForm

    What's the exact error message, please?

  12. #12
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Add Clipboard Image to UserForm

    Which line of code does it break at? Perhaps try putting a small delay before that line?

  13. #13
    Registered User
    Join Date
    03-08-2017
    Location
    Durban, South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: Add Clipboard Image to UserForm

    Run-time error '1004'
    CopyPicture method of Range class failed

    It fails at
    Please Login or Register  to view this content.
    Thank you.

  14. #14
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Add Clipboard Image to UserForm

    I'd suggest adding this at the top of your module
    Please Login or Register  to view this content.
    And then this before the CopyPicture line
    Please Login or Register  to view this content.
    The sleep time is in milliseconds - adjust if required. I wrote some screen capture code once that stopped working after we upgraded to Windows 7. This fixed it for me - hope it helps you too!

  15. #15
    Registered User
    Join Date
    03-08-2017
    Location
    Durban, South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: Add Clipboard Image to UserForm

    Awesome, thank you.

    That seems to have done it.

  16. #16
    Registered User
    Join Date
    11-04-2014
    Location
    Portugal
    MS-Off Ver
    XL2013/XL365
    Posts
    88

    Re: Add Clipboard Image to UserForm

    Hi, I know it's been 4 years since this post, but I can't get it to work on Excel365 - Windows10.
    Any help would be appreciated.

  17. #17
    Registered User
    Join Date
    04-02-2021
    Location
    CHina
    MS-Off Ver
    2016
    Posts
    1

    Re: Add Clipboard Image to UserForm

    Quote Originally Posted by JCabral View Post
    Hi, I know it's been 4 years since this post, but I can't get it to work on Excel365 - Windows10.
    Any help would be appreciated.
    Hi, i also struggeled to get it working on Excel365 and Windows10, both 64bit.

    i finally got it working with this ppicture-modul:
    Quote Originally Posted by xlnitwit View Post
    To work with either you would require something like this- attached as the code seems to be too long to paste inline.
    then i use it like this

    Please Login or Register  to view this content.
    hope this helps

  18. #18
    Registered User
    Join Date
    11-04-2014
    Location
    Portugal
    MS-Off Ver
    XL2013/XL365
    Posts
    88

    Re: Add Clipboard Image to UserForm

    Thanks for your reply, can you put a file with an example? Can't put it working
    Last edited by AliGW; 04-18-2022 at 05:28 AM. Reason: PLEASE don't quote unnecessarily!

  19. #19
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: Add Clipboard Image to UserForm

    Administrative Note:

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query, and attach a workbook showing what you have tried.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 07-14-2016, 04:59 AM
  2. [SOLVED] Copy userform to clipboard as image
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2016, 09:02 AM
  3. Is there command to save clipboard as [image] file
    By riwiseuse in forum Excel General
    Replies: 0
    Last Post: 06-05-2016, 01:12 PM
  4. [SOLVED] Using a Userform to Browse image file then paste selected image to sheet?
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-05-2015, 05:42 PM
  5. [SOLVED] How to apply Image borders to an image that my excel vba userform pastes in a word doc?
    By CaptainCool in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-11-2014, 05:40 PM
  6. [SOLVED] VBA to transfer image FROM userform image control TO a worksheet cell
    By Zoediak in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2014, 02:51 PM
  7. Copying an image into the clipboard
    By Omri6 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-08-2008, 03:32 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1