Malik Al-Amin was telling us:
Malik Al-Amin nous racontait que :
Thanks Jezebel
Is it more appropriate to use one over the other? Basically what I'm
doing is I have document1 open and I run a macro that opens up a
document2. This macro copies certain paragraphs from document one and
certain paragraphs from document two and merges them together in
document3. I was using the range object as I was under the impression
that this was the object to use if you're not highlighting anything
in the document interface. is my logic wrong? When merging things
back together I want to keep the original formatting of the
paragraphs from their original sources. It was explained how to do
this via the selection object. Is that the way I should be heading
with this?
I think you are doing the right thing, especially if you are manipulating
many bits of texts from one document to another. In those cases, Selection
can lead to all kinds of troubles. Generally speaking, I avoid the Selection
objects, except in short simple projects or in cases where I have no choice
(Information Property, Pre-defined Bookmarks, etc.)
Just use something like:
'_______________________________________
Dim Doc1 As Document
Dim Doc2 As Document
Dim MyRange As Range
Dim MyTarget As Range
Set Doc1 = ActiveDocument
Set Doc2 = Documents.Open("C:\MyDoc.doc")
Set MyRange = Doc1.Paragraphs(2).Range.FormattedText
Set MyTarget = Doc2.Range
With MyTarget
.Collapse WdCollapseEnd
.InsertParagraph
.FormattedText = MyRange
End With
'_______________________________________
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org