Access to Word 2003 VBA Macro

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Access to Word 2003 VBA Macro

Post by armsys » Sat Apr 12, 2008 5:53 am

1. How can MS script directly access Word 2003 objects?
2. How can MS script run Word 2003 macro such as normal.module1.myMacro?
Thanks.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sat Apr 12, 2008 5:58 am

I'm not certain but perhaps something like what is explained for Excel here:
http://www.mjtnet.com/forum/viewtopic.php?t=3825

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Apr 12, 2008 6:26 am

Code: Select all

VBSTART

Sub RunWordAndMacro(doc,macro)

  Dim WordApp As Object
  Set WordApp = CreateObject("Word.Application")
  WordApp.Visible = True
  WordApp.documents.Open doc
  WordApp.Run macro
  WordApp.Quit

End Sub

VBEND

VBRun>RunWordAndMacro,c:\somedoc.doc,MyMacro
Last edited by Marcus Tettmar on Sat Apr 12, 2008 6:48 am, edited 1 time in total.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sat Apr 12, 2008 6:46 am

Hi Marcus and JPL,
Thanks your quick help. I didn't know a MS script could call Word 2003 macros. That's new to me. It's amazingly simple and straightforward.
Thaks again.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sat Apr 12, 2008 8:05 am

Macrus,

When trying out your suggested script:
VBSTART
Sub RunWordAndMacro(doc,macro)
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True
WordApp.documents.Open doc
WordApp.Run macro
WordApp.Quit
End Sub

VBEND

VBRun>RunWordAndMacro,C:\Temp\¤å¥ó.rtf,Sub_assignObj

I encounter the following error:
Microsoft VBScript compilation error:1025
Expected end of statement
Line 3, Column 14

I don't understand why. Line 3 is just a simple delcaration: Dim WordApp As Object.

Please help. Thanks.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sat Apr 12, 2008 11:01 am

After removing the statement--Dim WordApp As Object, the script can run but generate the following Macro Scheduler error:
Forms.Form.1 :-2147352573
Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.
Line 8, Column 2

How can I resovle the problem?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sat Apr 12, 2008 12:12 pm

Please ignore my last two posts. I solved the problem by correcting the macro naming convention. Thanks.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts