# how to write to clipboard in CF_HTML



## outmarcus (Aug 27, 2005)

How can I write to clipboard in CF_HTML format (not TEXT format) using 
Javascript or another FF/IE compatible language? 

I have an equivalent Visual Basic Code which does this but it 
obviously cannot be used in FF/IE.. 


Here is the Visual Basic code: 


_____ 
' Set HTML into the drop source's IDataObject 
Private Sub SetHTMLData(Data As DataObject, htmlData As String) 


Dim cf As Integer 
Dim byteArray() As Byte 
Dim ch As String 
Dim i As Long 


' Normalize the atom returned from RegisterClipboardFormat 
If CF_HTML > 32767 Then 
cf = 65536 - CF_HTML 
cf = -cf 
Else 
cf = CF_HTML 
End If 


' Allocate an array of bytes to hold the HTML 
ReDim byteArray(0 To Len(htmlData)) 


' Copy the data from the BSTR into the byte array 
For i = 1 To Len(htmlData) 
ch = Mid(htmlData, i, 1) 
byteArray(i - 1) = Asc(ch) 
Next 


' Set the data into the IDataObject and set the clipboard format 
Data.SetData byteArray, cf 


End Sub 
_____


----------

