简体   繁体   English

如何在VBA宏中将远程MS Word文档与活动文档合并?

[英]How to merge a remote MS Word document with the active document in a VBA macro?

Frontend 前端

In the "frontend" I have a macro linked to a button in my command bar within Word. 在“前端”中,我有一个宏链接到Word中命令栏中的按钮。 Purpose of this button is to allow users to compare the current document with its previous version. 此按钮的目的是允许用户将当前文档与其以前的版本进行比较。

Backend 后端

In the backend I have a Java EE server and Alfresco running with a few servlets. 在后端,我有一个Java EE服务器和运行有一些servlet的Alfresco。 One of these servlets currently returns .doc document when given the document's name. 给定文档名称后,这些servlet之一当前会返回.doc文档。 So I just need to call it with the good name containing the version I want and it returns me the document I asked for. 因此,我只需要使用包含我想要的版本的好名字来调用它,它就会向我返回我所需要的文档。

Ideal workflow 理想的工作流程

So the ideal workflow for a user would be the following : 因此,对于用户而言,理想的工作流程如下:

  • User opens a MS Word document 用户打开一个MS Word文档
  • User clicks on a button in the command bar 用户单击命令栏中的按钮
  • User gets a new document containing a merged version of both its current doc and the one returned by the server 用户获取一个新文档,该文档包含其当前文档和服务器返回的文档的合并版本

What I want to know 我想知道什么

The challenging part for me is the one regarding VB6. 对我来说最具挑战性的部分是有关VB6的部分。 I know that I can merge docs with ActiveDocument.Merge FileName:="path_to_file", MergeTarget:=wdMergeTargetSelected but 我知道可以将文档与ActiveDocument.Merge FileName:="path_to_file", MergeTarget:=wdMergeTargetSelected但是

  1. How to call a servlet that returns a Word Document that I can use in my VB script? 如何调用返回可在VB脚本中使用的Word文档的servlet?
  2. How to interpret the result of this call so I can pas it to the Merge function and create my merged document? 如何解释此调用的结果,以便可以将其粘贴到Merge函数并创建合并的文档?

Thank you for you help. 谢谢你的帮助。

You open a document using Documents.Open . 您使用Documents.Open打开Documents.Open See F1-help for help on the different options and paramteters. 有关不同选项和参数的帮助,请参阅F1帮助。

Option Explicit

Sub OpenDoc()

    Dim oDoc As Document

    Set oDoc = Documents.Open(FileName:="FILENAME.docx")

    Call oDoc.Merge("PATH-TO-OTHER-DOCUMENT.docx")

    Set oDoc = Nothing

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM