Consulting

Results 1 to 7 of 7

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

  1. #1

    PowerPoint VBA - Is It Possible To Delete A Macro Added As An Action Setting

    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.

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Quote Originally Posted by John Wilson View Post
    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!

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    [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.

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  7. #7
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •