Domanda

I have a macro that copies from a small word document to a main word document, inserting at a bookmark. The content that is copies is within a table and has various rows and columns containing data and a few images.

My code is as follows:

Set SmallDoc = Documents.Open("small.doc")
Selection.WholeStory
Selection.Copy

'Paste document content at bookmark
Set MasterDoc = Documents.Open("main.doc")
Selection.GoTo What:=wdGoToBookmark, Name:="placeToPaste"
Selection.Paste

Issue:

The formatting is mostly kept, except the images transfer across and look as though they are cut off. Is there a way to keep the entire source formatting or some way to fix this issue?

È stato utile?

Soluzione

Although I can't seem to find if it's possible to ensure source formatting is kept, in my particular case this was helpful in keeping the images displaying correctly:

'Opens and selects the current document
Dim CurrentDoc As Document
Set CurrentDoc = Documents.Open('c:/your/file/here.doc')
CurrentDoc.Select

'Cycle each image and change its formatting
For Each Pic In Selection.InlineShapes
    Pic.ConvertToShape.WrapFormat.Type = wdWrapSquare
Next

Altri suggerimenti

Try

Selection.PasteAndFormat wdFormatOriginalFormatting

It has worked for me when copying a TextBox (drawing) and a jpeg along with text.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top