+ Reply to Thread
Results 1 to 2 of 2

txtbox no right click copy menu available?

  1. #1
    Registered User
    Join Date
    06-16-2005
    Posts
    62

    txtbox no right click copy menu available?

    I need to highlight the contents of a textbox and copy it to the clipboard. Momentarily it will be pasted into another application as the file name to save that applications file as.

    I can drag the mouse and highlight the .Text. I can then Ctrl-c to copy the text to the clipboard. Then I can Ctrl-V or left click the mouse and paste the .Text and save the file.

    I would like to right click the mouse and have it select and copy the txtbox.Text to the clipboard automatically.

    I must be missing something simple.

    Thanks for your suggestions,

    Craigm

  2. #2
    Registered User
    Join Date
    06-16-2005
    Posts
    62

    Copies automatically when .Text changes ready for pasting.

    http://www.cpearson.com/excel/clipboar.htm

    I used his solution to make this work flawlessly.
    ------------------------------
    Copying To The Clipboard

    To access the Windows Clipboard from VBA, you must go through an intermediate object of the DataObject type. If your VBA procedure will be working with the clipboard, declare a NEW DataObject object with the following statement.

    Dim MyDataObj As New DataObject

    The SetText method of the DataObject variable is used to store a text string or numeric value in the variable For example:

    MyDataObj.SetText "This Is A Text String" Or
    MyDataObj.SetText 123.456

    This sets the contents of MyDataObj to a value. To copy the contents of the variable MyDataObj to the Windows clipboard, use the PutInClipboard method .

    MyDataObj.PutInClipboard


    ------------

    Public Sub PutOnClipboard(Obj As Variant)
    Dim MyDataObj As New DataObject
    MyDataObj.SetText Format(Obj)
    MyDataObj.PutInClipboard
    End Sub


    Public Function GetOffClipboard() As Variant
    Dim MyDataObj As New DataObject
    MyDataObj.GetFromClipboard
    GetOffClipboard = MyDataObj.GetText()
    End Function


    Public Sub ClearClipboard()
    Dim MyDataObj As New DataObject
    MyDataObj.SetText ""
    MyDataObj.PutInClipboard
    End Sub

    ----------------------------

    Elegant solution

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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