+ Reply to Thread
Results 1 to 19 of 19

Macro not copying to Clipboard

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Macro not copying to Clipboard

    For years I've been using an "indent to clipboard" macro from https://en.wikibooks.org/wiki/Visual..._Code_Indenter

    In recent months it's stopped working for me. Or rather, it may be working, because it says it is, but it's not, because when I paste instead of my indented code I get two Ascii symbols.

    I had a similar result to putting data in the clipboard on this post: https://www.excelforum.com/excel-pro...ml#post5589918
    But I don't know how to alter the "Indent" macro to apply that solution.
    I know I'm not stupid, but I suspect I'm a lot stupider than I think I am

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Macro not copying to Clipboard

    I just tried that code and also got ?? as the result. I will look at it further but it is a s***load of code.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Macro not copying to Clipboard

    Yep, it's a lot. But I notice, just like in the other post I reference, if I close Windows Explorer the code works right, so it's in the part of the code where it copies to the clipboard.

    BTW, heading home now, won't be back until Monday, so I hope A) you practice Thanksgiving and B) You enjoy your Thanksgiving.

  4. #4
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Macro not copying to Clipboard

    I tried the code and it indented my code nicely (thanks this could be useful).
    does it fail for you on any code? even a simple one?

    I think I do remember getting "??" (box around the '?' i think) when running some simple code to populate clipboards and that it was working on some computers and not others.
    (at the time I just bypassed it by populating a sheet and copying it out again thus filling my clipboard)

    *Edit : for what it is worth - my explorer is open both file and internet as well as chrome and Firefox.
    Last edited by scottiex; 11-24-2021 at 06:43 PM.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Macro not copying to Clipboard

    yep, any code, as long as Explorer is open. Closed, it works fine.

  6. #6
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Macro not copying to Clipboard

    is it on any page that it is open?

    does ie have programmatic access to your clipboard in the security settings?

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Macro not copying to Clipboard

    It's a long standing bug with the dataobject (started with Win8). Use API calls instead to put the text in the clipboard.
    Rory

  8. #8
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,220

    Re: Macro not copying to Clipboard

    Recently, I came across a cool solution that does not require Win API. Instead it uses the Microsoft HTML Object Library which is fast and ubiquitous.
    Please Login or Register  to view this content.
    Artik

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Macro not copying to Clipboard

    I'd suggest making the argument a Variant, not String. I've seen issues with that method otherwise - see for example this thread: https://www.excelforum.com/excel-pro...clipboard.html

    IMO, the API route is safer.

  10. #10
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,220

    Re: Macro not copying to Clipboard

    Quote Originally Posted by rorya View Post
    I'd suggest making the argument a Variant, not String.
    Note that the argument is later assigned to the variable of type Variant.

    Quote Originally Posted by rorya View Post
    IMO, the API route is safer.
    For now, I like the API-free solution. But time will verify that.

    Artik

  11. #11
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Macro not copying to Clipboard

    Quote Originally Posted by Artik View Post
    Note that the argument is later assigned to the variable of type Variant.
    I confess I overlooked that. Seems like an unnecessary step when you could just make the input a variant?

  12. #12
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,220

    Re: Macro not copying to Clipboard

    I am not the author of this function, so I do not know exactly what the author had in mind that the argument was of the String type. From what I can see, the JScriptTypeInfo object clearly expects text. I did a little experiment changing the argument type to Variant. When I passed a number to the function, I got the error: -2147352319 - Method 'setData' of object 'JScriptTypeInfo' failed. And this is probably the main reason the argument is of the String type. However, the Variant type used later is probably supposed to support the 64-bit version of Office.

    Artik

  13. #13
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Macro not copying to Clipboard

    Artik,
    Thanks for the function, but I need help in figuring out how to plug it into the bigger macro. Can you help?

  14. #14
    Forum Contributor
    Join Date
    01-02-2020
    Location
    Idaho, USA
    MS-Off Ver
    365
    Posts
    273

    Re: Macro not copying to Clipboard

    Just my 2 cents worth... but I have had some trouble with using the clipboard in VBA if my clipboard app in Windows 10 is turned on. It keeps a record of everything that you copy to the clipboard, so if you have that turned on, maybe it's messing up somehow when the code changes what is in the clipboard.

  15. #15
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,381

    Re: Macro not copying to Clipboard

    This is how you put stuff in your clipboard

    Please Login or Register  to view this content.

  16. #16
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Macro not copying to Clipboard

    Quote Originally Posted by JEC. View Post
    This is how you put stuff in your clipboard
    That uses the dataobject which has the bug that started this thread…

  17. #17
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,220

    Re: Macro not copying to Clipboard

    Jomili,
    Please Login or Register  to view this content.
    Artik

  18. #18
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,381

    Re: Macro not copying to Clipboard

    It is but this uses late binding. Should give it a try

  19. #19
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Macro not copying to Clipboard

    The binding context makes no difference to the bug, I'm afraid. It's still the DataObject after all.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copying Multiple Cells to Clipboard
    By rameesareno in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-18-2009, 10:09 PM
  2. Copying an image into the clipboard
    By Omri6 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-08-2008, 03:32 AM
  3. [SOLVED] Copying more than 255 Characters to the Clipboard
    By biker in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2006, 09:10 AM
  4. Copying more than 255 Characters to the Clipboard
    By biker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2006, 04:10 AM
  5. [SOLVED] Copying more than 255 Characters to the Clipboard
    By biker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2006, 04:05 AM
  6. Copying to Excel Clipboard
    By S Smolski in forum Excel General
    Replies: 0
    Last Post: 05-05-2006, 12:30 PM
  7. [SOLVED] Copying to Clipboard query.
    By Rodney in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 05-02-2005, 05:06 PM
  8. Copying Text to Clipboard using a Button
    By robertguy in forum Excel General
    Replies: 0
    Last Post: 02-14-2005, 03:51 AM

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