PDA

View Full Version : PowerPoint VBA - Is It Possible To Delete A Macro Added As An Action Setting



ajarmstron
07-24-2020, 02:16 AM
Hi - I made a PowerPoint, which contains coding that creates some rectangular shapes and adds a macro to them by the below code. My question is, is it possible to use VBA coding to then remove the macros associated with these shapes?



stringName = "NameOfString"
sMacroName = "NameOfMacro"

Set MyShape = MyDocument.Shapes(stringName)


With MyShape.ActionSettings(ppMouseClick)
.Run = sMacroName
.Action = ppActionRunMacro
End With


Thank you for any comments.

John Wilson
07-24-2020, 07:06 AM
Macros are NOT really added to shapes you are adding an action to the shape to run a macro. Many shapes could run the same macro.

Do you maybe mean remove the action from the shape so it no longer runs the macro?

ajarmstron
07-24-2020, 07:52 AM
Macros are NOT really added to shapes you are adding an action to the shape to run a macro. Many shapes could run the same macro.

Do you maybe mean remove the action from the shape so it no longer runs the macro?

Yes! I am trying to avoid code from running when it is not needed.

Thank you!

Paul_Hossler
07-24-2020, 06:57 PM
I'm assuming that

1. You add a shape and click code

2. During the presentation you click the shape to run the associated macro

3. Sometime during the presentation something or a macro or you have some way of deciding that the shape click code should no longer be run if the shape is clicked ?????

4. Add a global Boolean flag and test before running the shape's macro

5. or change the .Run to a 'Do Nothing' macro





Public bDontRun as Boolean

.....
sMacroName = "NameOfMacro"
Set MyShape = MyDocument.Shapes(stringName)


With MyShape.ActionSettings(ppMouseClick)
.Run = sMacroName
.Action = ppActionRunMacro
End With


in a shape or macro, change bDontRun to True

'-----------------------------------------------------
Sub NameOfMacro

if bDontRun Then Exit Sub

End Sub

ajarmstron
07-25-2020, 07:30 AM
[QUOTE=Paul_Hossler;403472]I'm assuming that

1. You add a shape and click code

2. During the presentation you click the shape to run the associated macro

3. Sometime during the presentation something or a macro or you have some way of deciding that the shape click code should no longer be run if the shape is clicked ?????

4. Add a global Boolean flag and test before running the shape's macro

5. or change the .Run to a 'Do Nothing' macro


[CODE]

Thanks for the post Paul - I am very familiar with a variety of ways of handling programming objects they don't accept any more inputs. My issue is that when the PowerPoint is run the mouse cursor changes when it goes over an object with an action setting. I personally think it looks better (and is safer) that when an on screen shape is no longer part of the activity that the cursor does not change. I think the only way to do this is to remove the action setting outright from the object? I believe when you write "Do Nothing" macro you are referring to a macro with no code. However, the problem with this is that the mouse cursor will still change.

John Wilson
07-25-2020, 07:44 AM
Not sure I understand what you are trying to do but to kill the Action setting

Omit the .Run line

and set .Action to ppActionNone

ajarmstron
07-25-2020, 08:00 AM
Hi John - thank you very much for your post. I am a teacher that is making educational resources. My new skill learnt during the lockdown has been VBA coding in PowerPoint! I believe that if there is another lockdown then using PowerPoint is a great way of providing interactive resources.

So you are stating the following code should be used?

stringName = "NameOfString"
sMacroName = "NameOfMacro"

Set MyShape = MyDocument.Shapes(stringName)

With MyShape.ActionSettings(ppMouseClick)
.Action = ppActionNone
End With