Log in

View Full Version : Solved: Using Range.InsertFile with RTF files



Adamski
04-05-2012, 04:51 AM
Hello,

I have a database which has a load of data in richtext format.
I have code to export the RTF strings to a word document.
Currently I am doing this by copy-paste via the windows clipboard. It works, but disables the clipboard for the duration of the export. This is very annoying.
I am updating the code to dump the RTF strings to .rtf files and then insert these files into the word document. No Copy Pasting but more File Operations - Create Write Read Delete.

Using range.InsertFile, how do I get the range of the inserted file so I can collapse it and insert the next?
(This is not going at the end of the document)

Or is there a third way to parse RFT into Word?

Thanks,

Pho3NiX
04-07-2012, 05:08 AM
Sorry I can't post link yet, but see here
(words mvps org /faqs/macrosvba/GetRngToEndOfInsertFile htm)*



Dim rngStart As Range
Dim rngEnd As Range

Set rngStart = whatever (where you want the file inserted)
rngStart.Collapse direction:=wdCollapseStart
Set rngEnd = rngStart.Duplicate
rngEnd.InsertParagraph
rngStart.InsertFile "C:\Temp\test.doc"
rngEnd.Characters.Last.Delete

Your file will be between rngStar.Start and rngEnd.Start

-----------

Also be aware that you'll loose formating of the first section of insertFile. This is why i always start those file with a section break.

-----------

Alternatively if both document are open in word you can use something like
DestinationRange.formattedText = SourceRange

Adamski
04-13-2012, 01:30 AM
As the link says: "Nuts and sledgehammers..."
But it works,
Thanks