ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   txtbox no right click copy menu available? (https://www.excelbanter.com/excel-programming/356800-txtbox-no-right-click-copy-menu-available.html)

Craigm[_46_]

txtbox no right click copy menu available?
 

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

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

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

I must be missing something simple.

Thanks for your suggestions,

Craig

--
Craig
-----------------------------------------------------------------------
Craigm's Profile: http://www.excelforum.com/member.php...fo&userid=2438
View this thread: http://www.excelforum.com/showthread.php?threadid=52529


Craigm[_47_]

txtbox no right click copy menu available?
 

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


--
Craigm
------------------------------------------------------------------------
Craigm's Profile: http://www.excelforum.com/member.php...o&userid=24381
View this thread: http://www.excelforum.com/showthread...hreadid=525298



All times are GMT +1. The time now is 08:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com