Can't execute word macro from excel

2019-07-24 08:15发布

I simply cannot get this to work. I am trying to run a word Macro from excel (before importing a table). Here is the code:

Option Explicit

Sub RunWdMacro()

  Dim WordApp As Word.Application
  Dim WordDoc As Word.Document
  Dim wdFileName As Variant
  Set WordApp = CreateObject("Word.Application")

  wdFileName = Application.GetOpenFilename("Word files ,*.doc;*.docx;*.docm", , _
    "Browse for file containing table to be imported")
  WordApp.Visible = True
  'change TEST to the name of your macro in word
  WordApp.Run "Delcolumnbreaks"

  WordApp.Quit SaveChanges:=wdDoNotSaveChanges
  Set WordApp = Nothing
End Sub

I am prompting for a word file to open, but it errors out at:

 WordApp.Run "Delcolumnbreaks"

With error "Run-time error '-2147352573 (800200003) Can't run the specified macro. The macro is in the normal section as module 1

Any thoughts?

Thanks

0条回答
登录 后发表回答