Resetting OnAction in Office 2003

M

mark-dale

Please can anyone tell me how to reset the OnAction property in
PowerPoint 2003?

I'm hooking into the menus to call my own macros using the OnAction
property eg

Dim myFileMenu As Object
Dim myButton As CommandBarButton

Set myFileMenu = Application.CommandBars("File")

Set menuItem = myFileMenu.FindControl(Type:=msoControlButton,
id:=CommandBars("File").controls("Open...").id)
menuItem.OnAction = "DocumentOpen"

and when I want to remove my hooks I simply set the OnAction to an
empty string.

menuItem.OnAction = ""

This works fine for all versions of all Office apps EXCEPT PowerPoint
2003 which gives an error when the line is encountered.

PLEASE... can anyone tell me how to do it?

Thanks

Mark
 
S

Steve Rindsberg

I haven't run into this one yet, but that's not to suggest it's not
happening to you.
As a workaround, create a subroutine that does nothing:

Sub DummyToKeepPPT2003Happy()
' There. Happy now?
End Sub

As needed, set OnAction to this sub instead of to null string.

Does that do it for you?

--
Posted to news://msnews.microsoft.com
Steve Rindsberg, PPT MVP
PowerPoint FAQ - www.pptfaq.com
PPTools - www.pptools.com
===============================
 
C

Chirag

Does your subroutine get called when the menu item is clicked - does
DocumentOpen get called? In my version, it does not get called.

The way to capture button events is through a WithEvents variable:

Create a class (say, ButtonEventsClass) with the following contents:
---
Option Explicit

Public WithEvents CBB As CommandBarButton

Private Sub CBB_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)

MsgBox "Hi"
End Sub
---

In your modules, declare a global variable (say OpenBtn) of type
ButtonEventsClass. Modify your code snippet to:

---
Dim myFileMenu As Object
Dim myButton As CommandBarButton

Set myFileMenu = Application.CommandBars("File")

Set myButton = myFileMenu.FindControl(Type:=msoControlButton, _
Id:=CommandBars("File").Controls("Open...").Id)
Set OpenBtn = New ButtonEventsClass
Set OpenBtn.CBB = myButton
---

When you want to remove the hooks, set OpenBtn to Nothing.

- Chirag

PowerShow - View multiple shows simultaneously
http://officerone.tripod.com/powershow/powershow.html
 
M

Mark D

Unfortunately that would mean in my case that the standard
File>>Open... command wouldn't do anything!

Thanks for the suggestion though.

Mark
 
M

Mark D

Thanks Chirag... I'll give your suggestion a try.

It's a shame that I'll have to modify my code in 3 places, as I have
identical code in Word, Excel and PowerPoint working for every version
except PowerPoint 2003... of course, I could just modify PowerPoint,
but then maintenance becomes an issue... and all because OnAction
starts behaving differently. Oh well, such is the joy of VBA
development!

Thanks again

Mark
 
S

Steve Rindsberg

Unfortunately that would mean in my case that the standard
File>>Open... command wouldn't do anything!

I'm a little confused ... weren't you trying to set OnAction to "" before?
 
M

Mark D

Setting OnAction = "" means (for all but PowerPoint 2003) do the
default action associated with the menu item, ie in my example, do
standard open processing, it doesn't actually mean 'do nothing'!

So in my Auto_Open I set the File>>Open OnAction = "DocumentOpen",
then in Auto_Exit, or if the user asks to disable my add-in, I set the
File>>Open OnAction = "" so the normal document opening behaviour
occurs.
 
S

Steve Rindsberg

Setting OnAction = "" means (for all but PowerPoint 2003) do the
default action associated with the menu item, ie in my example, do
standard open processing, it doesn't actually mean 'do nothing'!

Learn something new around here all the time. I didn't realize that ...
thanks.
So in my Auto_Open I set the File>>Open OnAction = "DocumentOpen",
then in Auto_Exit, or if the user asks to disable my add-in, I set the
File>>Open OnAction = "" so the normal document opening behaviour
occurs.

I wonder if

Application.CommandBars("WhicheverMenuYou'reWorkingWith").Controls("TheContr
olInQuestion").Reset

would do it for you.
 

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