I am trying to paste Rich Text strings into Excel.
I can copy to the clipboard and paste into Word just fine.
I copy them to the clipboard with this
Public Sub Paste(sRTF As String)
'sRTF represents the rich text formatted string to paste into Word
RTB1.TextRTF = sRTF
'Copy the contents of the Rich Text to the clipboard
Dim lSuccess As Long
Dim lRTF As Long
Dim hGlobal As Long
Dim lpString As Long
lSuccess = OpenClipboard(Me.hwnd)
lRTF = RegisterClipboardFormat("Rich Text Format"
lSuccess = EmptyClipboard
hGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, Len(sRTF))
lpString = GlobalLock(hGlobal)
CopyMemory lpString, ByVal sRTF, Len(sRTF)
GlobalUnlock hGlobal
SetClipboardData lRTF, hGlobal
CloseClipboard
GlobalFree hGlobal
End Sub
But when I try to paste into Excel it fails.
ActiveSheet.Paste Destination:=Worksheets("Sheet1".Range("D22"
It appears Excel is not interpreting the data from the clipboard.
I have tried to view the data on the clipboard
MsgBox (Clipboard.GetText())
But I get a blank msgbox
After the app crashes I can open Word and paste and I get the string I copied there.
Any Ideas??
I can copy to the clipboard and paste into Word just fine.
I copy them to the clipboard with this
Public Sub Paste(sRTF As String)
'sRTF represents the rich text formatted string to paste into Word
RTB1.TextRTF = sRTF
'Copy the contents of the Rich Text to the clipboard
Dim lSuccess As Long
Dim lRTF As Long
Dim hGlobal As Long
Dim lpString As Long
lSuccess = OpenClipboard(Me.hwnd)
lRTF = RegisterClipboardFormat("Rich Text Format"
lSuccess = EmptyClipboard
hGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, Len(sRTF))
lpString = GlobalLock(hGlobal)
CopyMemory lpString, ByVal sRTF, Len(sRTF)
GlobalUnlock hGlobal
SetClipboardData lRTF, hGlobal
CloseClipboard
GlobalFree hGlobal
End Sub
But when I try to paste into Excel it fails.
ActiveSheet.Paste Destination:=Worksheets("Sheet1".Range("D22"
It appears Excel is not interpreting the data from the clipboard.
I have tried to view the data on the clipboard
MsgBox (Clipboard.GetText())
But I get a blank msgbox
After the app crashes I can open Word and paste and I get the string I copied there.
Any Ideas??