VB Excel – 当用Excel打开Word文档时,当我尝试使用ActiveDocument时,出现'Variable not defined'错误
我有一个要求从Excel中打开一个Word文档,并使用Excel电子表格中的文本replaceWord文档中的文本框中的文本。
我用Wordlogging了一个macros,它说使用ActiveDocument
,但是当我尝试在Excel中的代码中使用这个,我得到一个Variable not defined error
。
这是我的代码 –
Dim objWord As Object Set objWord = CreateObject("Word.Application") objWord.Visible = True objWord.Documents.Open "C:\Users\kmccorma\Desktop\ReportPage.doc" ActiveDocument.Shapes("Text Box 12").Select
我尝试objWord.Shapes,但我得到一个错误,说对象不支持这个属性。
我可以看到Shapes属性可用于ActiveChart
,我需要做一些ActiveChart
来使这个工作?
对VB还是比较新的,所以任何帮助将不胜感激。
这是因为,Excel不能识别ActiveDocument
是什么。 我会build议使用对象。 看到这个例子。
Dim objWord As Object, objDoc As Object Set objWord = CreateObject("Word.Application") objWord.Visible = True Set objDoc = objWord.Documents.Open("C:\Users\kmccorma\Desktop\ReportPage.doc") With objDoc.Shapes("Text Box 12") '~~> Do Something '.Select End With