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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy & Paste oleRTF into Word - results not Rich Text 1

Status
Not open for further replies.

kazl

Programmer
Dec 9, 2002
68
GB
Hello Everybody

I'm held up on an RTF Rich Text problem. I want to copy the rich text from an active form into Word, via the clipboard.

I have tried this with the code from Phil Hawkin's article (recommended by Mike Lewis in thread1254-845690). But all of my attempts still paste the fully coded text into Word.

Copy and paste with the keyboard from my form into Word gives the perfectly formatted rich text. But this does have to be automated.

I've tried this using SelStart and SelLength. Then
_CLIPTEXT = oUserNotes.oleRTF.SelText
This pastes plain text.

So does:
_CLIPTEXT = oUserNotes.oleRTF.TextRTF
loWord.Selection.Paste
and so does
loWord.Selection.PasteSpecial

I've even tried all of this again with Phil's points about activating the clipboard in Rich Text Format too but I still get either plain text or it includes all the formatting codes.

I'm back to square one. Why won't my clipboard handle the change to RTF? Can anyone help please?

Kaz
 

Kaz,

I'm sorry I can't answer this, but if you like I will pass this on to Phil, who I see from time to time. I can't say for sure if he can help you either, as I know he is in the middle of a big project right now, but it might be worth a shot.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
OK. Thanks Mike.

Actually, the reason it has to go into Word now is because the oleRTF control is misbehaving. E.G. It won't let users type the number 1, except with the numeric pad, which is strange. I'll come back to it later I guess.

Thanks for replying.

Karen
 
Here's a function that does the trick (based on Phil's documentation)
You only have to pass the rtf text en and a rangeobject (word) as paramaters and the function will paste the rtf text into that range.

Code:
FUNCTION rtftorange
LPARAMETERS pcRtfTekst, poRange
*
*	Places a rtf text in poRange
*
    LOCAL hActiveWindow,lcSource, lnAllocSize, hMem, lnAddr
	
	
    DECLARE INTEGER CloseClipboard 				IN win32api 
    DECLARE INTEGER EmptyClipboard 				IN win32api 
    DECLARE INTEGER GetActiveWindow 		IN win32api 
    DECLARE INTEGER GetClipboardData 		IN win32api	INTEGER 
    DECLARE INTEGER IsClipboardFormatAvailable 	IN win32api	INTEGER 
    DECLARE INTEGER OpenClipboard 				IN win32api	INTEGER
    DECLARE INTEGER RegisterClipboardFormat 	IN win32api	STRING 
    DECLARE INTEGER RtlMoveMemory 				IN win32api STRING @, INTEGER, INTEGER 
    DECLARE INTEGER SetClipboardData 			IN win32api INTEGER, INTEGER

	
    * First we post the RTF text to the clipboard in 
    * the ordinary text formats that are supported 
    * by _CLIPTEXT. There are about 4 or 5 of them.
	_CLIPTEXT = pcRtfTekst
	
	* Obtain a handle for the active window.
	LOCAL hActiveWindow
	hActiveWindow = GetActiveWindow()

	* Open the clipboard with an association to the 
	* active window.
	lSuccess = OpenClipboard(hActiveWindow)

	* Register RTF as a valid clipboard format. If 
	* already registered this will return the 
	* existing handle, otherwise generate a new one.
	LOCAL hRTF
	hRTF = RegisterClipboardFormat("Rich Text Format")

	* Obtain handle for data posted on the clipboard 
	* in text format.
	LOCAL hData
	#DEFINE CF_TEXT 1
	hData = GetClipboardData(CF_TEXT)

	* Re-post the same memory block to the clipboard 
	* as RTF, then close it.
	= SetClipboardData(hRTF, hData)
	= CloseClipboard()


	* Paste the text into the word document and make 
	* sure it's visible.
	poRange.Paste()

	* Tidy up.
	= OpenClipboard(hActiveWindow)
	= EmptyClipboard()
	= CloseClipboard()

   
        
ENDFUNC
 
Hi Stefan5627

Thank you very much for posting your function.

Initially I was getting the same problems BUT on a fresh attempt on my laptop this works perfectly.

Seems my old faithful PC has its own way of doing things, even with the same versions of Word and VFP.

If I can find out why then I'll post a note of the problem.

Have a star for saving the day.

Kaz





 
Glad you got it working, thanks for the star

Hope you find out what the problem was on your old pc,
would be interesting to know.


Stefan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top