copy & pasting text but keeping format

K

Katy White

I need to concatenate the contents of multiple documents into a singe
document. I used VB 6 but am using a word document object. I have most of
this working but I am having trouble keeping the formatting of the original
document when I paste it into the new document. Currently I am using --

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.HomeKey unit:=wdStory

Word.Application.Selection.WholeStory
Word.Selection.Copy
'close the file without changing anything
Word.Application.Saved = True
Word.Applicaton.Close

wdDoc1.Activate 'destination file

Selection.Paste
'end old stuff
Selection.WholeStory
Selection.EndKey unit:=wdStory
'insert a section break
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.HeaderFooter.LinkToPrevious = False

This code works perfectly in VBA but for some reason I loose the formatting
in VB. All the information comes over correctly (it's actually all in tables
with headers and footers on each page and some portions of text are bolded)
but the font size does not come over. I tried copying styles from the
original to the new (Normal in the original is 10 pt and Normal in the next
doc is 12 pt) but that doesn't help either.

Suggestions?
 
J

jay

Does the text have any overrides - paragraph or character formatting on
top of the 'normal' style?
I guess you could loop through the paragraph ranges and remove
overrides or apply the style of your choice?
Or- do a s&r for the style/formatting ?
 
K

Katy White

Hi Jay,

The original docs are in RTF ... everything is Normal as a style (they are
SAS 9 output) but there is some formatting applied (mostly just bold to some
sections). When I copy everything over I keep everything (including tables
and bold in the appropriate places) but the font goes from 10 pt to 12 pt. I
tried copying the style from the old doc to the new one but that didn't seem
to work:

With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "Normal"
.XMLSchemaReferences.AutomaticValidation = True
.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
End With
Application.OrganizerCopy Source:= strSource, Destination:= strDest, _
Name:="Normal", Object:=wdOrganizerObjectStyles

The source doc font size for normal is 10pt and the normal.dot font size is 12

Is there something I'm not doing correctly here?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top