且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用vba将一个word文档的内容复制到另一个word文档中

更新时间:2023-10-15 11:57:46

使用这些命令,您可以在您使用的 Document 以及复制和粘贴元素之间切换:

Using commands such as these you can switch between which Document you're using and copy and paste elements:

ThisDocument.Activate 'Sets the main document active
Documents("Name.doc").Activate 'Activates another document

您可以使用复制命令在文档中插入、复制和粘贴内容.

You can insert, copy and paste things in and out of documents using copy commands.

ThisDocument.Range.InsertAfter("String") 'Insert text

Selection.WholeStory 'Select whole document
Selection.Expand wdParagraph 'Expands your selection to current paragraph
Selection.Copy 'Copy your selection
Documents("name.doc").Activate 'Activate the other document
Selection.EndKey wdStory 'Move to end of document
Selection.PasteAndFormat wdPasteDefault 'Pastes in the content

然后,您可以对其进行格式化,或使用之前的原始格式复制并粘贴它们.

You can then go and format such, or copy and paste them with original formatting from before.