我正在尝试自动化Excel VBA正在完成所有工作的一些报告生成.我的雇主有一套标准化的模板,所有文件都应该从中生成.我需要从Excel VBA填充其中一个模板.Word模板广泛使用VBA.
这是(部分)我的Excel VBA代码:
Sub GenerateReport() ' (Tables, InputDataObj)
' code generating the WordApp object (works!)
WordApp.Documents.Add Template:="Brev.dot"
' Getting user information from Utilities.Userinfo macro in Document
Call WordApp.Run("Autoexec") ' generating a public variable
Call WordApp.Run("Utilities.UserInfo")
' more code
End sub
Run Code Online (Sandbox Code Playgroud)
在Word VBA Autoexec模块中,user定义并声明了一个名为的公共变量.模块中的Userinfo子Utilities组件填充user.这两个例程都是在没有任何VBA投诉的情况下运行的.我希望能够访问user我的Excel VBA中的变量,但我收到以下错误
编译错误:尚未在此上下文中创建的变量.
如何在Excel VBA中访问Word VBA变量?我认为它或多或少是一样的?
编辑:user变量是Type仅使用String属性定义的用户.复制填充user变量的Word VBA函数绝对可行,只需要比我更多的工作......