Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Copy and Paste RTF string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
melon - 13 Mar 2008 20:40 GMT
I have a RTF string strTest set to the following:

{\rtf1\ansi\ansicpg1252\deff0\deftab360{\fonttbl{\f0\fswiss Arial;}
{\f1\fswiss\fcharset0 Arial;}}
{\*\generator Riched20 5.50.99.2050;}\viewkind4\uc1\pard
\f0\fs20\lang1033\par
\par
\f1 TEST\f0\par
}

I am trying to copy it using the following

Dim MyData As DataObject
Set MyData = New DataObject

MsgBox strTest               ' make sure I am copying the correct
thing
MyData.SetText strTest , -16639                      ' VBCFRTF doesn't
work
MyData.PutInClipboard

However, nothing is put into the clipboard, when I try to run

objWord.ActiveDOcument.Bookmarks("Body").Range.Paste

I will get a Command Fail error.
Klaus Linke - 13 Mar 2008 20:59 GMT
Hi,

I'd save the RTF string as a temp.RTF file in the Windows Temp folder,
insert that RTF file in the document, then kill the file.
Unless it results in a real speed problem, that'd probably be the simplest
solution.

Klaus
melon - 13 Mar 2008 21:16 GMT
> Hi,
>
[quoted text clipped - 4 lines]
>
> Klaus

How do you do that?  For some reason my search term "VBA save rtf
file" is not very helpful.
Klaus Linke - 13 Mar 2008 21:57 GMT
> How do you do that?  For some reason my search term
> "VBA save rtf file" is not very helpful.

Quick and dirty/not debugged:

Sub RTF_Place(sText As String)
 Dim iFile As Integer
 iFile = FreeFile
 Open "C:\Windows\Temp\temp.RTF" For Binary As #iFile
 Put #iFile, , sText
 Close #iFile
 Selection.InsertFile FileName:="C:\Windows\Temp\temp.rtf", Range:="", _
   ConfirmConversions:=False
 Kill "C:\Windows\Temp\temp.RTF"
End Sub

Sub Test_RTF_Place()
   Dim sText As String
   sText = "{\rtf1\ansi\ansicpg1252\deff0\deftab360{\fonttbl{\f0\fswiss
Arial;}{\f1\fswiss\fcharset0 Arial;}}{\*\generator Riched20
5.50.99.2050;}\viewkind4\uc1\pard\f0\fs20\lang1033\par\par\f1 TEST\f0\par}"

   Call RTF_Place(sText)

End Sub

If you plan to use the macro on several computers, it might be a good idea
to google for a safe way to determine the Temp folder... or maybe just use
the current folder -- you'll delete the file anyway.

Regards,
Klaus

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.