简体   繁体   中英

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. 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. One of these servlets currently returns .doc document when given the document's name. 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
  • 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. I know that I can merge docs with ActiveDocument.Merge FileName:="path_to_file", MergeTarget:=wdMergeTargetSelected but

  1. How to call a servlet that returns a Word Document that I can use in my VB script?
  2. How to interpret the result of this call so I can pas it to the Merge function and create my merged document?

Thank you for you help.

You open a document using Documents.Open . See F1-help for help on the different options and paramteters.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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