pastespec命令
<P>回帖发生错误;我重新发了:)</P><P>GetFormat、GetText 和 SetText 方法示例</P>
<P>下例用 GetFormat、GetText 和 SetText 方法在 DataObject 和剪贴板之间传输文本。</P>
<P>用户把文本键入文本框然后单击 CommandButton1,把文本以标准文本格式传输到 DataObject。单击 CommandButton2,在 DataObject 中检索文本。单击 CommandButton3,用自定义格式把文本从 TextBox1 复制到 DataObject。单击 CommandButton4,用自定义格式在 DataObject 中检索文本。</P>
<P>若要使用该示例,请将示例代码复制到某窗体的声明变量部分。请确保该窗体包含: </P>
<P>名为 TextBox1 的文本框。</P>
<P><BR>名为 CommandButton1 到 CommandButton4 的四个命令按钮控件。</P>
<P><BR>名为 Label1 的标签。 <BR>Dim MyDataObject As DataObject</P>
<P>Private Sub CommandButton1_Click()<BR>'把标准格式放到剪贴板上<BR> If TextBox1.TextLength > 0 Then<BR> Set MyDataObject = New DataObject<BR> MyDataObject.SetText TextBox1.Text<BR> Label1.Caption = "Put on D.O."<BR> CommandButton2.Enabled = True<BR> CommandButton4.Enabled = False<BR> End If<BR>End Sub</P>
<P>Private Sub CommandButton2_Click()<BR>'从剪切板得到标准格式<BR> If MyDataObject.GetFormat(1) = True Then<BR> Label1.Caption = "Std format - "_ <BR> & MyDataObject.GetText(1)<BR> End If<BR>End Sub</P>
<P>Private Sub CommandButton3_Click()<BR>'把自定义格式放到剪切板上<BR> If TextBox1.TextLength > 0 Then<BR> Set MyDataObject = New DataObject<BR> MyDataObject.SetText TextBox1.Text, 233<BR> Label1.Caption = "Custom on D.O."<BR> CommandButton4.Enabled = True<BR> CommandButton2.Enabled = False<BR> End If<BR>End Sub</P>
<P>Private Sub CommandButton4_Click()<BR>'从剪切板得到自定义格式<BR> If MyDataObject.GetFormat(233) = True Then<BR> Label1.Caption = "Cust format - "_ <BR> & MyDataObject.GetText(233)<BR>End If<BR>End Sub</P>
<P>Private Sub UserForm_Initialize()<BR> CommandButton2.Enabled = False<BR> CommandButton4.Enabled = False<BR>End Sub<BR></P>
页:
[1]