【问题标题】:Synchronizing Word BuildingBlocks over network but with offline support通过网络同步 Word BuildingBlocks,但支持离线
【发布时间】:2017-06-16 20:09:01
【问题描述】:

我在 VBA 中为 Word 2013 构建了一个自定义 BuildingBlock 管理系统,使用户能够更方便地对 BuildingBlocks 进行分类、过滤和使用。

这些块存储在.dotm 模板文件中,该模板文件附加到带有管理系统代码的.docm 文件中。后者的内容不时在全球范围内更新,每个用户的本地副本也可能包含单独的内容。所有用户都应该能够创建自动可供所有其他人使用的新块。此外,应该可以随时(在线、离线)使用本地块,只有创建/删除块需要网络连接。

这是一个试图解释连接的图形:

我的方法是在每次打开本地工作文件时以及在本地启动任何更改之前将存储文件从网络复制到本地。更改后,网络文件会立即更新。这样,其他用户的更改很可能不会被覆盖(仅当它们同时发生时)并且所有用户都有一个最新的块集合来使用。

问题: 我无法覆盖正在使用的文件 - 因为工作文件引用了 .dotm 块存储文件,它会在后台打开。暂时分离模板也不起作用:我尝试使用

ActiveDocument.AttachedTemplate = ""

但这很不稳定,不会在我测试过的系统上处理(不同的配置)。我不知道为什么,但我不能依赖这样的解决方案。

这是我的问题: 你知道这样做的方法吗?有没有最佳实践?

感谢任何提示。

【问题讨论】:

    标签: vba templates ms-office ms-word


    【解决方案1】:

    对于任何对此主题感兴趣的人:我必须为此创建一个解决方法。

    存储积木的模板需要关闭才能被覆盖,所以我写了一个小批处理脚本在工作文件关闭后进行更新。要返回上一个操作或完成它,批处理文件会创建一个带有交换参数的临时文本文件,然后可以在打开工作文件时读取该文件。这是批处理文件:

    @echo off
    :: Batch file for updating the local libraries [referenced as library and cat files in the following]
    :: Parameters: 
    ::  %1 - caller file path
    ::  %2 - update scenario
    ::  %3 - local tool dir path
    ::  %4 - library file name
    ::  %5 - cat file name
    ::  %6 - network library dir path
    ::  %7 - tooldata folder name
    
    SET n=0
    SET f=0
    
    IF "%~1"=="" (
      echo No arguments passed.
      Goto NoArguments
    )
    
    :: Build local and remote paths to the libraries
    SET LocalLib=%~3%~4
    SET LocalCat=%~3%~5
    SET NetworkLib=%~6%~4
    SET NetworkCat=%~6%~5
    
    :: Wait for a maximum of 16 sec until the local library gets released.
    :: If its still in use afterwards, abort the copy actions.
    
    :Loop
    SET /A n=n+1
    IF %n% EQU 10 (
      Goto FileNotClosed
    ) ELSE (
      2>nul (
        >>%LocalLib% echo off
      ) && (SET f=1)
      IF %f% EQU 0 (
        Ping 1.1.1.1 -n 2 -w 1 | find /V "Ping" > nul
        Goto Loop
      ) ELSE (
         Goto StartCopy
      )
     )
    
    :StartCopy
    :: Calling document is closed so it should be save to copy the network libraries to the local destination
    xcopy %NetworkLib% %LocalLib% /y /q
    xcopy %NetworkCat% %LocalCat% /y /q
    
    :FileNotClosed
    :: Finally write results of the actions to a xargs.txt file
    @echo scenario=%~2>"%~3%~7\xargs.txt"
    IF %f% EQU 0 ((@echo success=0)>>"%~3%~7\xargs.txt") ELSE ((@echo success=1)>>"%~3%~7\xargs.txt")
    
    :: Reopen the caller file
    %1
    
    :NoArguments
    

    此解决方案出现的问题是,在工作文件中创建的任何数据在关闭文件时都会丢失。这就是为什么我还需要将任何用户表单/构建块数据存储在额外的临时文件中。

    例如,现在创建一个新的构建块的工作方式如下:用户在工作文件对话框中输入所有必要的信息。完成后,数据将保存在临时文件中,updater.bat 启动并关闭工作文件。更新器复制最新的文件并重新启动工作文件,工作文件从上述 .txt 文件中读取更新结果,完成创建,将本地文件重新上传到网络并清理混乱。

    【讨论】:

      猜你喜欢
      • 2016-07-04
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 2011-09-28
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多