如何在execl宏中启动WORD文档运行WORD宏?

2024-12-01 07:17:56
推荐回答(1个)
回答1:

Dim wrdApp As Object
Dim wrdDoc As Object

On Error GoTo myErr
Set wrdApp = GetObject(, "Word.Application") ‘有Word进程时
Set wrdDoc = wrdApp.Documents.Open("Word文件地址")
wrdApp.Visible = True '显示Word
wrdApp.Run "Word 宏名"

Set wrdDoc = Nothing
Set wrdApp = Nothing
Exit Sub

myErr:
Set wrdApp = CreateObject("Word.Application") ‘没有Word进程时
Set wrdDoc = wrdApp.Documents.Open("Word 文件地址")
wrdApp.Visible = True '显示Word
wrdApp.Run "Word 宏名"

Set wrdDoc = Nothing
Set wrdApp = Nothing