Share via


WorksheetBase.PasteSpecial Method

Pastes the contents of the Clipboard onto the worksheet, using a specified format. Use this method to paste data from other applications or to paste data in a specific format.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public Sub PasteSpecial ( _
    format As Object, _
    link As Object, _
    displayAsIcon As Object, _
    iconFileName As Object, _
    iconIndex As Object, _
    iconLabel As Object, _
    noHTMLFormatting As Object _
)
public void PasteSpecial(
    Object format,
    Object link,
    Object displayAsIcon,
    Object iconFileName,
    Object iconIndex,
    Object iconLabel,
    Object noHTMLFormatting
)

Parameters

  • format
    Type: System.Object

    A string that specifies the Clipboard format of the data. Common format strings include "HTML", "Bitmap", "Hyperlink", "Unicode Text", and "Text".

  • link
    Type: System.Object

    true to establish a link to the source of the pasted data. If the source data is not suitable for linking or the source application does not support linking, this parameter is ignored. The default value is false.

  • displayAsIcon
    Type: System.Object

    true to display the pasted object as an icon. The default value is false.

  • iconFileName
    Type: System.Object

    The name of the file that contains the icon to use if DisplayAsIcon is true.

  • iconIndex
    Type: System.Object

    The index number of the icon within the icon file.

  • noHTMLFormatting
    Type: System.Object

    true to remove all formatting, hyperlinks, and images from HTML; false to paste HTML as is. The default value is false.

Remarks

If you do not know which string to pass to the Format parameter, you can view the strings that are compatible with the data on the Clipboard by trying the paste command in Excel . Copy the data to the Clipboard, use the Paste Special command in Excel, and then view the formats listed in the Paste Special dialog box.

NoHTMLFormatting will only matter when Format = "HTML". In all other cases, NoHTMLFormatting will be ignored.

You must select the destination range before you use this method.

This method might modify the sheet selection, depending on the contents of the Clipboard.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Examples

The following code example places HTML onto the Clipboard and then uses the PasteSpecial method to paste the contents of the Clipboard into cell A1. Note that the example selects the range before calling the PasteSpecial method.

This example is for a document-level customization.

Private Sub PasteSpecialText()
    Clipboard.SetText("<HTML><BODY><STRONG>Paste Special Text Example" & _
        "</STRONG></BODY></HTML>")

    Me.Range("A1").Select()
    Me.PasteSpecial(Link:=False, DisplayAsIcon:=False)
End Sub
private void PasteSpecialText()
{
    Clipboard.SetText("<HTML><BODY><STRONG>Paste Special Text Example" +
        "</STRONG></BODY></HTML>");

    this.Range["A1"].Select();
    this.PasteSpecial(missing, false, false);
}

.NET Framework Security

See Also

Reference

WorksheetBase Class

Microsoft.Office.Tools.Excel Namespace