+ Reply to Thread
Results 1 to 13 of 13

Convert Formula to VBA, copy 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

    Convert Formula to VBA, copy to Clipboard

    For many, many years I've been using the below code to
    1) Convert a formula in the cell to it's VBA equivalent code and
    2) copy it to the clipboard so it's ready to be pasted into the macro I'm creating.

    The code works well, and it's very handy, but it has a problem;
    if I have any Explorer windows open the formula is NOT copied to my clipboard, but only two ASCII symbols.
    When I see that I have to go and close Explorer and try it again.

    I'm wondering if I could put either a check in the macro to see if Explorer is open, and if it is either display a message or close Explorer.

    Or even better, is there a way to rewrite the macro to work regardless of what Explorer windows are open?

    Please Login or Register  to view this content.
    I know I'm not stupid, but I suspect I'm a lot stupider than I think I am

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Convert Formula to VBA, copy to Clipboard

    Give this a try - using a different object library:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  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: Convert Formula to VBA, copy to Clipboard

    Hmm, got a Compile error on "Replace", saying "Wrong number of arguments or invalid property assignment"

  4. #4
    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: Convert Formula to VBA, copy to Clipboard

    Tried a combination of old and new. This one errors on the "CreateObject" line, saying "Invalid Argument".
    Please Login or Register  to view this content.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: Convert Formula to VBA, copy to Clipboard

    The code is correct. Do you have a routine called Replace anywhere? If so, change this code to use VBA.Replace
    Remember what the dormouse said
    Feed your head

  6. #6
    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: Convert Formula to VBA, copy to Clipboard

    I don't have a "Replace" macro, but I tried your "VBA." suggestion. Still getting the "Invalid Argument" error.
    Please Login or Register  to view this content.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: Convert Formula to VBA, copy to Clipboard

    Oh yes - you need to declare the VBA_formula variable as Variant, not String.

  8. #8
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Convert Formula to VBA, copy to Clipboard

    All working as originally posted for me. Strange. See animated GIF in the attached ZIP.

    WBD
    Attached Files Attached Files

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: Convert Formula to VBA, copy to Clipboard

    I get the same error as the OP with Excel 2016 and Win10.

  10. #10
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Convert Formula to VBA, copy to Clipboard

    Quote Originally Posted by rorya View Post
    I get the same error as the OP with Excel 2016 and Win10.
    Oh. On which line?

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: Convert Formula to VBA, copy to Clipboard

    On the setData line

  12. #12
    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: Convert Formula to VBA, copy to Clipboard

    Sorry, got called away. Replacing string with variant did the trick! AND, it seems to work when Windows Explorer is open. Thanks! You guys are the best!

  13. #13
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Convert Formula to VBA, copy to Clipboard

    Hey. Cool. Glad we got there. Sometimes tricky when you're accessing external libraries with different versions of Excel.

    WBD

+ 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. Copy From Clipboard to Find Value on Pivot Table, Copy to Different Cell
    By msdcanto in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-07-2018, 01:21 PM
  2. Copy from clipboard
    By brent_milne in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-03-2015, 03:39 PM
  3. Show data > copy data to clipboard > hide data... clipboard data is gone??
    By DaveSev in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-26-2015, 10:16 AM
  4. Copy and Paste Formula: Bypassing the Clipboard
    By new2excel2012 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-12-2012, 05:32 AM
  5. How to copy to clipboard?
    By jp001 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-17-2011, 01:23 AM
  6. Copy one cell to an other but colors do not copy. While not using clipboard to copy.
    By chuckchuckit in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-19-2010, 03:08 AM
  7. [SOLVED] Convert CSV from clipboard into a transposed list (part solution provided)
    By Andibevan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2006, 02:55 PM

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