See Also Example
Puts a text string in the operating environment Clipboard using the specified Clipboard format.
Syntax
Clipboard.SetText data [,format]
Remarks
The SetText method has these parts:
Part Description
data String data to be placed on the Clipboard.
format One of the following Clipboard formats recognized by Visual Basic. If format is omitted, CF_TEXT is assumed.
Symbolic constant Value Clipboard format
CF_LINK &HBF00 DDE conversation information
CF_TEXT 1 Text
Note Symbolic constants for Clipboard format definitions can be found in the Visual Basic file CONSTANT.TXT. When placed in any module in a project, the symbolic names can be used in all your form and code modules.
Clipboard Object
GetFormat Method
GetText Method
SetData Method
The example uses the SetText method to copy text from a text box to the Clipboard. To try this example, paste the code into the Declarations section of a form with a text box named Text1. Then press F5 and click the form.
Sub Form_Click ()
Const CF_TEXT = 1 ' Define bitmap format.
Dim I, Msg, Temp ' Declare variables.
On Error Resume Next ' Set up error handling.
Msg = "Type anything you like into the text box below."
Text1.Text = InputBox(Msg) ' Get text from user.
Msg = "Choose OK to copy the contents of the text box "
Msg = Msg & "to the Clipboard."
MsgBox Msg ' Display message.
ClipBoard.Clear ' Clear Clipboard.
Clipboard.SetText Text1.Text ' Put text on Clipboard.
If Clipboard.GetFormat(CF_TEXT) Then
Text1.Text = "" ' Clear the text box.
Msg = "The text is now on the Clipboard. Choose OK "
Msg = Msg & "to copy the text from the Clipboard back "
Msg = Msg & "to the text box."
MsgBox Msg ' Display message.
Temp = Clipboard.GetText(CF_TEXT) ' Get Clipboard text.
For I = Len(Temp) To 1 Step -1 ' Reverse the text.
Text1.Text = Text1.Text & Mid(Temp, I, 1)
Next I
Else
Msg = "There is no text on the Clipboard."
MsgBox Msg ' Display error message.
End If
End Sub