Ozgrid Excel Help & Best Practices Forums


XL Templates | XL Add-ins | XL Training | XL Estimating | XL Scheduling | XL Recovery | XL Trading | XL Financial | XL Conversion | XL Charting


+ Reply to Thread
Results 1 to 5 of 5

Thread: Copy Textbox Text To Clipboard

  1. #1
    Join Date
    21st March 2007
    Posts
    2

    Copy Textbox Text To Clipboard


    Download Active Data For Excel > > DETAILS > >
    Hello All-
    I am just trying to copy the contents of a TextBox onto the clipboard so that the text can be pasted in a Word document or anywhere as just text.

    My textbox is named:
    Sheets("Type1").TextBox1

    Any ideas how to accomplish this?

    Thanks!

  2. #2
    Join Date
    10th February 2003
    Location
    Palm Beach, Florida
    Posts
    1,590

    Re: Copy Textbox Text To Clipboard

    In the past, I've used a backhanded approach with InputBox/SendKeys to quickly dump text to the clipboard. I'll share my trick with you if you promise not to tell anyone...

    Code:
    Sub TextCopy()
        Application.SendKeys ("^c~")
        InputBox "clipboard", , Sheets("Sheet1").TextBox1.Text
    End Sub

    Sure, it works with your textbox but it's also kinda neat to remember for dumping strings in general to the clipboard.
    Last edited by Aaron Blood; March 22nd, 2007 at 03:37.
    Sub All_Macros(Optional control As Variant)

  3. #3
    royUK is offline Publishes Private Messages
    Join Date
    26th January 2003
    Location
    Lincolnshire,UK
    Posts
    12,876

    Re: Copy Textbox Text To Clipboard

    Here's another way
    Code:
       Dim objData As DataObject
        Dim strClipBoard As String
        Set objData = New DataObject
        ' Clears the clipboard
        objData.SetText ""
        objData.PutInClipboard
        ' Puts the text from an textBox into the clipboard
        strClipBoard = Me.TextBox1.Value
        objData.SetText strClipBoard
        objData.PutInClipboard
        ' Gets the text on the clipboard into a string variable
        objData.GetFromClipboard
        strClipBoard = ""
        strClipBoard = objData.GetText

  4. #4
    Join Date
    10th February 2003
    Location
    Palm Beach, Florida
    Posts
    1,590

    Re: Copy Textbox Text To Clipboard

    I believe you only expose the DataObject if you already have a userform open in your app. Which in this case... I had not detected.
    Last edited by Aaron Blood; March 22nd, 2007 at 03:59.
    Sub All_Macros(Optional control As Variant)

  5. #5
    royUK is offline Publishes Private Messages
    Join Date
    26th January 2003
    Location
    Lincolnshire,UK
    Posts
    12,876

    Re: Copy Textbox Text To Clipboard


    Create Excel dashboards quickly with Plug-N-Play reports.
    I thought the OP was talking about a TextBox on a UserForm, I didn't notice the sheets reference.
    Last edited by royUK; March 22nd, 2007 at 04:30.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Possible Answers

  1. Putty - Copy Terminal Output to Clipboard in Rich Text Format
    By Dave Hawley in forum Excel RSS Feed Discussions
    Replies: 0
    Last Post: January 23rd, 2009, 21:47
  2. Copy Textbox Text To Clipboard
    By Upside in forum EXCEL HELP
    Replies: 19
    Last Post: May 24th, 2008, 07:51
  3. Copy Textbox Text Into Another Textbox
    By markronz in forum EXCEL HELP
    Replies: 1
    Last Post: March 21st, 2007, 07:18
  4. Copy Textbox Text When Cursor Moved From Textbox
    By senarumugam2003 in forum EXCEL HELP
    Replies: 5
    Last Post: February 7th, 2007, 20:14
  5. UserForm TextBox Paste From Clipboard
    By CarolP in forum EXCEL HELP
    Replies: 7
    Last Post: April 23rd, 2003, 17:55

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