+ Reply to Thread
Results 1 to 20 of 20

Save VBA Variable to Clipboard

  1. #1
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Save VBA Variable to Clipboard

    Hello All.. I'm trying to save a variable to the clipboard so that I can paste it to another area.

    Background is that there's an online game I play that you can sell in game items on a forum. The forum can support certain tags to set up a table but trying to code a table for it pretty much makes me go crosseyed or want to drink a fifth of whiskey. So I'v generated some VBA to take the table I make in Excel and turn it into the code for the forum. I've learned after creating this code, that I cannot copy from the msgbox when it displays the code. I have tried various solutions I've found when googling but none of them have worked.

    End result shoudl be that it saves the variable Msgcode to the clipboard so I can just jump over to the forum and paste it.... Please let me know what I'm missing.


    Thanks in advance.

    Vamosj



    Please Login or Register  to view this content.
    Janos S. Vamos
    Data Systems Technician/Fire Controlman PO1(SW/AW)
    US Navy Retired


    Remember, Record Macro can be your friend for figuring out solutions.

    Good or Bad, let me know how I did by clicking on the "Add Reputation" * just to the lower left of here. it only takes a few seconds to let someone know.

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Save VBA Variable to Clipboard

    Added a couple of lines to your code:
    Please Login or Register  to view this content.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save VBA Variable to Clipboard

    Hello vamosj,

    An easier way than using the DataObject is to copy MsgCode to a cell on the worksheet. You can then easily copy it to the clipboard. The changes are in bold text.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Save VBA Variable to Clipboard

    Thank you both for your reply


    Quote Originally Posted by tlafferty View Post
    Added a couple of lines to your code:[code]
    This is the one I've found using Google but for some reason doesn't work. I get a Compile error: User-Defined type not defined whenever I try and Dim the Dataobject.


    Leith - I was thinking about trying it but didn't figure it would work with my chr(13) in the coding but decided to give it a shot... It works. Thanks for your input.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save VBA Variable to Clipboard

    Hello vamosj,

    Glad to help a fellow squid.

  6. #6
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Save VBA Variable to Clipboard

    Back again with oe more quick ? about this. When I go to copy this I'm getting the " at the beginning and end of the code so when I paste it, the " is showing up when I don't want it to. Is there any way to remove this?

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save VBA Variable to Clipboard

    Hello Janos,

    Do you mean you when you paste it on the Excel worksheet or in Notepad?

  8. #8
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Save VBA Variable to Clipboard

    When I paste it into notepad

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save VBA Variable to Clipboard

    Hello Janos,

    I can't reproduce the problem. Can you post an sample Notepad file?

  10. #10
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Save VBA Variable to Clipboard

    I'll just post it and wrap some code around it... This is a straight ctrl+v paste

    Please Login or Register  to view this content.
    See how when I paste it there is the " at the beginning and another " at the end. I know this is normal with any text value but I would like to remove it as the quotation marks do show up in the forum when the table is placed. The user now has to go in, locate, and delete the quotation marks.

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save VBA Variable to Clipboard

    Hell Janos,

    Since I can not reproduce the problem using Ctrl+V, it is possible to remove the beginning and ending quotes within the file using VBA. To do so requires that the Notepad file first be saved. You can then use this macro to remove the quotes. You will need to change the file path and file name to what you are using.

    Please Login or Register  to view this content.

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Save VBA Variable to Clipboard

    Probably this code performs the same job:

    Please Login or Register  to view this content.
    Last edited by snb; 09-23-2011 at 04:08 AM.



  13. #13
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Save VBA Variable to Clipboard

    Not looking to save or open a notepad file. What I'm trying to do is the individual using this starts the macro, the macro takes the table into excel, and converts it to a string of code that can be pasted into a forum. Let me go ahead and upload my file..

    I tried pasting it to notepad and for some reason it doesn't have the " show up on it, but when I post it to the forum it does.

    To run the macro, go to the table tab and hit ctrl+m
    Attached Files Attached Files

  14. #14
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save VBA Variable to Clipboard

    Hello Janos,

    Okay, I see what you mean. The quotes being added by the forum are most likely due to HTML code tags that included in the text. Placing the code inside quotes prevents the HTML code from being executed. Nothing you can due about that.

  15. #15
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Save VBA Variable to Clipboard

    Here is an image of what is happenning if I post it as is... You can see the " in the upper left hand corner. There is another after the table also..


    http://imgur.com/tV8gu

  16. #16
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Save VBA Variable to Clipboard

    so I guess this brings me back to my original question... Is there a way to save the variable to the clipboard other than placing it in a cell and do the ole automated copy and paste routine?

    Thanks for sticking with me on this.

  17. #17
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save VBA Variable to Clipboard

    Hello Janos,

    Does this site allow you to post HTML code? A lot of sites don't for security reasons.

  18. #18
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Save VBA Variable to Clipboard

    So I went back to tlafferty's thread to try it again.... For some reason this time it worked which is really weird because I added the lines verbatum and I kept getting an object define error... This time it's working like a charm... The only thing I can think of is that it wa getting hung up after I already had an error the first time I tried it.. After closing the program and restarting it (a few days later I might add), it is now running like a champ.... Sometimes I hate computers. Especially when they make you look like the fool..

    Well this I think this is fully solved now.... Thanks everyone for your inputs.

    Quote Originally Posted by tlafferty View Post
    Added a couple of lines to your code:
    Please Login or Register  to view this content.

  19. #19
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save VBA Variable to Clipboard

    Hello Janos,

    When I was a DS in the Navy, I had a rubber mallet in my tool box. Just for situations like this one.

  20. #20
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Save VBA Variable to Clipboard

    Despite the mallet you probably overlooked my suggestion in post #12, which does everything (reading & writing, no clipboard needed) in 1 go.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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