4

Excel's Application object has a ClipboardFormats property. From the docs:

Returns the formats that are currently on the Clipboard, as an array of numeric values.

However, when I run the following code:

var app = new ActiveXObject('Excel.Application');
app.Visible = true;
var results = new VBArray(app.ClipboardFormats).toArray();
app.Quit();
window.alert(results.join(','));

I get back:

0, 44, 50

0 corresponds to XlClipboardFormat.xlClipboardFormatText, but the other values don't have matching enum members in the XlClipboardFormat enum.

What do 44 and 50 mean as clipboard format values?

Zev Spitz
  • 13,950
  • 6
  • 64
  • 136

1 Answers1

5

Don't know how much this helps get farther down the road, but taking the example from this source, I came up with the following test code:

Option Explicit

Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function EnumClipboardFormats Lib "user32" _
                         (ByVal wFormat As Long) As Long
Private Declare Function GetClipboardFormatName Lib "user32" _
                         Alias "GetClipboardFormatNameA" (ByVal wFormat As Long, _
                                                          ByVal lpString As String, _
                                                          ByVal nMaxCount As Long) As Long

Private Sub test()
    Dim results As Variant
    Dim fmtName As String
    Dim fmt As Long

    Range("A1").Copy
    results = Application.ClipboardFormats
    Debug.Print "For cell A1 (plain) = " & Join(results, ",")
    ClipboardFormats

    Range("A2").Copy
    results = Application.ClipboardFormats
    Debug.Print "For cell A2 (bold ) = " & Join(results, ",")
    ClipboardFormats

End Sub

Private Sub ClipboardFormats()
    Dim fmt As Long
    Dim fmtName As String
    Dim iClipBoardFormatNumber As Long

    OpenClipboard 0&
    If iClipBoardFormatNumber = 0 Then
        fmt = EnumClipboardFormats(0)
        Do While fmt <> 0
            fmtName = Space(255)
            GetClipboardFormatName fmt, fmtName, 255
            fmtName = Trim(fmtName)
            If fmtName <> vbNullString Then
                fmtName = Left(fmtName, Len(fmtName) - 1)
                Debug.Print "fmtName (" & fmt & ") = " & fmtName
            End If
            fmt = EnumClipboardFormats(fmt)
        Loop
    End If

    EmptyClipboard
    CloseClipboard
End Sub

The output is interesting, though not necessarily illuminating:

For cell A1 (plain) = 0,2,4,5,6,7,8,9,11,12,14,17,19,22,23,31,32,33,44,45,50,58,63
fmtName (49161) = DataObject
fmtName (50023) = Biff12
fmtName (50004) = Biff8
fmtName (50006) = Biff5
fmtName (49910) = XML Spreadsheet
fmtName (49349) = HTML Format
fmtName (49566) = CSV
fmtName (49273) = Rich Text Format
fmtName (49163) = Embed Source
fmtName (49156) = Native
fmtName (49155) = OwnerLink
fmtName (49166) = Object Descriptor
fmtName (49165) = Link Source
fmtName (49167) = Link Source Descriptor
fmtName (50003) = Link
fmtName (49154) = ObjectLink
fmtName (49171) = Ole Private Data
For cell A2 (bold ) = 0,2,4,5,6,7,8,9,11,12,14,17,19,22,23,31,32,33,44,45,50,58,63
fmtName (49161) = DataObject
fmtName (50023) = Biff12
fmtName (50004) = Biff8
fmtName (50006) = Biff5
fmtName (49910) = XML Spreadsheet
fmtName (49349) = HTML Format
fmtName (49566) = CSV
fmtName (49273) = Rich Text Format
fmtName (49163) = Embed Source
fmtName (49156) = Native
fmtName (49155) = OwnerLink
fmtName (49166) = Object Descriptor
fmtName (49165) = Link Source
fmtName (49167) = Link Source Descriptor
fmtName (50003) = Link
fmtName (49154) = ObjectLink
fmtName (49171) = Ole Private Data
PeterT
  • 8,232
  • 1
  • 17
  • 38