Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pasting RichText into Excel

Status
Not open for further replies.

cruzmsl

Programmer
Feb 13, 2002
18
US
I have a db with Rich Text strings in it I need to paste into Excel.
I can copy to the clipboard and paste into word just fine.
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("D2:D2")

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??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top