如何在另一个打开的Word文档VBA上从一个Word Document VBA设置模块变量? [英] How to set module variables from one Word Document VBA on another open Word Document VBA?

查看:595
本文介绍了如何在另一个打开的Word文档VBA上从一个Word Document VBA设置模块变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的是制作一些可以自动"移交"信息的文件。 

What I want is to make some documents which can do an automated 'handing over' of information. 

Document1有一个旧版本的代码。

Document1 has an older version of the code.

通过在Document1上使用update()宏,它会在指定的文件夹中检查是否存在新版本的文档(包含更新的宏)。 

By using an update() macro on Document1, it would check in a specified folder whether a new version of the document (with more recent macros) exist. 

如果它存在,它将以Document2打开新版本,并将一堆信息传递给Document2,包括一些VBA变量。 

If it exists, it would open the new version as Document2, and pass a bunch of information to Document2, including some VBA variables. 

我有点难以理解如何在Document1上运行的VBA代码中设置Document2范围内的变量。 

I am a bit stumped on how to set variables in the scope of Document2 from VBA code running on Document1. 

我不是说'文档变量',而是VBA变量,例如设置olddoc = Document2中的Document1(Document Object),因此它可以在Document1将责任传递给Document2之后将Document1移动到其他位置。 

I am not speaking od 'document variables', but VBA variables, such as setting an olddoc = Document1 (Document Object) inside Document2, so that it can move Document1 somewhere else after Document1 passes the responsibility to Document2. 

此外,我想从Document1的VBA代码触发Document2上的初始化函数,它在Document2的范围内运行(例如,THisDocument将指向Document 2,而不是Document1)。 

Also, I would like to trigger from Document1's VBA code an initialization function on Document2, which runs inside the scope of Document2 (such as e.g. THisDocument would point to Document 2, not Document1). 

是否有可能做到这一点,或者我尝试做太多了? 

Is it possible to do any of this, or am I trying to do too much? 

非常感谢帮助!

推荐答案

而不是放入宏一个Word文档(docm)你应该创建一个addin(dotm)并将所有代码和表单存储在其中。 然后加载插件(dotm),然后加载文档(docx,no macros)。 通过这种方式,您可以使插件保持最新状态
,并且您不必关心Word文档(docm)中的宏并使其保持最新状态。 您可以将插件放在Word STARTUP目录中,并在Word启动时加载。 您可能需要对代码进行一些细微的更改,但从长远来看,它将节省
。<

Rather then put macros in a Word document (docm) you should create an addin (dotm) and store all the code and forms in it.  You then load the addin (dotm) and then load the documents (docx, no macros).  This way you keep the addin up to date and you don't have to concern yourself with macros in Word docs (docm) and keeping them up to date.  You can put the addin in the Word STARTUP directory and it loads when Word starts.  You may have to do some minor changes to your code but it will save you tons in the long run.


这篇关于如何在另一个打开的Word文档VBA上从一个Word Document VBA设置模块变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆