Intercepting Word Commands, but using Build-in Macro

L

Lauro

I'd like to trap a Word command; and If a condition is true run
MyMacro, Else run the regular Word macro.

I know that I can trap the build-in macro just using the same name;
but then I won't be able to run the old macro anymore.

How can I achieve this?

thanks, Lauro
 
H

Helmut Weber

Hi Lauro,

like this:

Sub FilePageSetup()
Dim oDlg As Dialog
Set oDlg = Dialogs(wdDialogFilePageSetup) ' <<<
If Date = "2006-04-27" Then
MsgBox Date
Else
oDlg.Show
End If
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

Jezebel

There are no built-in macros. What you trap are built-in commands; but each
has an equivalent as a method, mostly of the application or document object,
as -- as Helmut explains -- as a dialog. From your own macro, call the
actual method you want.
 
K

Klaus Linke

With many commands, you can just use the same name as the command, but with
"WordBasic." in front (say, WordBasic.Bold).

But with dialogs (such as FilePageSetup) that doesn't work. If you really
want to run the built-in command, and not some corresponding VBA code (...
sometimes there are subtle differences), you should be able to use something
like

Application.EnableCancelKey = wdCancelDisabled
WordBasic.ToolsMacro Name:="FilePageSetup", Run:=1, Show:=2
Application.EnableCancelKey = wdCancelInterrupt

Klaus
 

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