Private Sub Command1_Click()
  Clipboard.SetText Label1.Caption
End Sub

解决方案 »

  1.   

    本示例使用 SetText 方法从一个文本框中复制文本到剪贴板。要检验此示例,可将本例代码粘贴到一个带有名为 Text1 的窗体的声明部分,然后按 F5 键并单击该窗体。Private Sub Form_Click ()
       Const CF_TEXT = 1   ' 定义位图各种格式。
       Dim I, Msg, Temp   ' 声明变量。
       On Error Resume Next   ' 设置错误处理。
       Msg = "Type anything you like into the text box below."
       Text1.Text = InputBox(Msg)   ' 取得用户正文。
       Msg = "Choose OK to copy the contents of the text box "
       Msg = Msg & "to the Clipboard."
       MsgBox Msg   ' 显示信息。
       ClipBoard.Clear   ' 清除剪贴板。
       Clipboard.SetText Text1.Text   ' 将正文放置在剪贴板上。
       If Clipboard.GetFormat(CF_TEXT) Then
          Text1.Text = ""   ' 清除该正文框。
          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   ' 显示信息。
          Temp = Clipboard.GetText(CF_TEXT)   ' 取得剪贴板正文。
          For I = Len(Temp) To 1 Step -1   ' 使该正文反向。
             Text1.Text = Text1.Text & Mid(Temp, I, 1)   
          Next I
       Else
          Msg = "There is no text on the Clipboard."
          MsgBox Msg   ' 显示错误信息。
       End If
    End Sub
      

  2.   

    而这个示例使用 GetText 方法从 Clipboard 对象中复制一个文字串至一字符串变量。要检验此示例,可将本例代码粘贴到一个带有一名为 Text1 的 TextBox 控件的窗体的声明部分,然后按 F5 键并单击该窗体。Private Sub Form_Click ()
       Dim I, Msg, Temp   ' 声明变量。
       On Error Resume Next   ' 设置错误处理。
       Msg = "Type anything you like into the text box below."
       Text1.Text = InputBox(Msg)  ' 取得用户正文。
       Msg = "Choose OK to copy the contents of the text box "
       Msg = Msg & "to the Clipboard."
       MsgBox Msg   ' 显示信息。
       Clipboard.Clear   ' 清除剪贴板。
       Clipboard.SetText Text1.Text  ' 将正文放置在剪贴板上。
       If Clipboard.GetFormat(vbCFText) Then
          Text1.Text = ""   ' 清除该正文框。
          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   ' 显示信息。
          Temp = Clipboard.GetText(vbCFText)   ' 取得剪贴板正文。
          For I = Len(Temp) To 1 Step -1   ' 使该正文反向。
             Text1.Text = Text1.Text & Mid(Temp, I, 1)   
          Next I
       Else
          Msg = "There is no text on the Clipboard."
          MsgBox Msg   ' 显示错误信息。
       End If
    End Sub