Application.Run error message

S

S1lverface

AAarrrrrrrrghhhhhhhh. Can anyone help please.

I have a Macro in Excle VBA which Opens my Word (.doc) file.

I then want it to run the chosen Macro called PrintBPs which is saved within
that word document under the path: Normal > Modules > NewMacros >

I cannot get it to tun the Macro. I have tried many combinations of
Application.run xxxxxxx

When I try Application.run MacroName:="PrintBPs" it tells me Named Argument
not found.

I am so lost. If anyone can help?

------------------------------------------
Below is the code

Sub OpenAWordDoc()
Dim WdApp As Object, WdDoc As Object

Set WdApp = CreateObject("Word.Application")

WdApp.Application.DisplayAlerts = False

WdApp.Documents.Open Filename:="""\\rdc-san04\Method\Briefing Pack -
SB.doc""", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto

WdApp.Windows.Application.Activate

WdApp.Visible = True

Application.Run "Normal.NewMacros.Modules.PrintBPs"
End Sub
 
D

Doug Glancy

Here's a stripped-down version that works for me:

Sub OpenAWordDoc()
Dim WdApp As Object, WdDoc As Object
Set WdApp = CreateObject("Word.Application")
With WdApp
.Application.DisplayAlerts = False
.Documents.Open Filename:="C:\Documents and Settings\doug\My
Documents\tester.doc"
'.Windows.Application.Activate
.Visible = True
.Run "PrintBPs"
End With
End Sub

I commented out the Windows.Application.Activate line because a) I didn't
know what it was supposed to do b) it didn't compile adn c) it seems to work
without it

Make sure your document path is correct and you should only need one set of
double-quotes.

I used the With WdApp statement in order to avoid referring to it
repeatedly. That will speed up your code.

hth,

Doug
 
H

Helmut Weber

Hi S1lverface,

try:

WdApp.run "PrintBPs"

As your code is, if refers to a macro in Excel.

Doug was quite right, by the way.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
S

S1lverface

Hi Guys.
Thanks very much for your help.

It doesn't work for me. Same error message. - I think it is due to
restrictions on my PC because it is a 'work' computer, and they do restrict
quite a few things. I can work without it. Thanks again.
 
H

Helmut Weber

Hi S1lverface,

there might be two causes,
the first is, what I wrote before.

The second might(!) be, according to your office-version,
that as opposed to the online-help,
"application.run" or here "WdApp.run"
doesn't like the full path to a macro.

It might accept only an application-wide unique macro-name.

By the way, a name "Modules" for a module seems rather unusual.
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top