See Also Example
Returns a text string from the operating environment Clipboard.
Syntax
Clipboard.GetText ([format])
Remarks
The argument format specifies one of the following Clipboard formats recognized by Visual Basic:
Symbolic constant Value Clipboard format
CF_LINK &HBF00 DDE conversation information
CF_TEXT 1 Text
If format is omitted, CF_TEXT is assumed.
If there is no text string on the Clipboard that matches the expected format, a zero-length string ("") is returned.
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
GetData Method
GetFormat Method
SetText Method
The example uses the GetText method to copy a text string from the Clipboard to a string variable. 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