Consulting

Results 1 to 17 of 17

Thread: Something wrong in XML? Or in VBA? Or something missing anywhere?

  1. #1
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location

    Something wrong in XML? Or in VBA? Or something missing anywhere?

    Hi there,

    I'm a big fan of toggle buttons :-)

    Well, in fact, I try to create one by myself for the first time. I read the tutorial of Gregory K. Maxey and tried to do it by myself in XML and PPTX 2010 for a TextBox appearing/getting deleted from the slidemaster. XML validation says: Well formed. VBA debugging doesn't say anything. But pressing my button says: Macro not found. I have no idea what went wrong and would appreciate your help very much.

    Thanks,
    RG

    This is what I wrote in XML:

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
    <ribbon startFromScratch="false">
    <tabs>
    <tab id="RGHomeTab" label="RG Home">
    <group id="ToggleTest" label="Test">
    <toggleButton id="customButton7" image="PH" onAction="RibbonControl.ToggleonAction" getPressed="RibbonControl.buttonPressed"/>
    </group>
    </tab>
    </Tabs>
    </ribbon>
    </customUI>
    My VBA code is:
    Sub ToggleonAction(control As IRibbonControl, pressed As Boolean)
      Select Case control.Id
        Case Is = "customButton7"
    
          If pressed Then
        Dim shp As Shape
    
        Set shp = Application.ActivePresentation.SlideMaster.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=39.118086, Top:=5.6692878, Width:=26.362188, Height:=21.826758)
    With shp
        .Fill.Visible = msoFalse
        .Line.Visible = msoFalse
        .Name = "Draftmaster"
        
    With .TextFrame
        .TextRange.Text = "Draft"
        .VerticalAnchor = msoAnchorTop
        .MarginBottom = "3,685037"
        .MarginLeft = "0"
        .MarginRight = "0"
        .MarginTop = "3,685037"
        .WordWrap = msoFalse
        
    With .TextRange
        .Font.Size = 12
        .Font.Name = "Arial"
        .Font.Color.RGB = RGB(89, 171, 244)
        .ParagraphFormat.Alignment = ppAlignLeft
    End With
    End With
    End With
    
          Else
            Application.ActivePresentation.SlideMaster.Shapes(Draftmaster) = Delete
          End If
      End Select
    End Sub

    Sub buttonPressed(control As IRibbonControl, ByRef toggleState)
      Select Case control.Id
        Case Is = "customButton7"
          If Not Application.ActivePresentation.SlideMaster.Shapes(Draftmaster) Then
            toggleState = True
          Else
            toggleState = False
          End If
      End Select
    End Sub
    Last edited by SamT; 06-02-2015 at 01:51 PM. Reason: Put Code Tags around code

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,787
    Location
    1. if you use the [#] icon you can paste your code between for formatting

    2. Your XML needs the onLoad plus some other tweaks

    3. The VBA needs the .Invalidate call to the ribbon

    4. I think the best way is to use a global Boolean to track pressed status

    5. I added the DRAFT to the current slide, not the master


    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="RibbonControl.OnRibbonLoad" >
    <ribbon>
    <tabs>
    <tab id="RGHomeTab" label="RG Home">
     <group id="ToggleTest" label="Test">
      <toggleButton id="customButton7" image="CuteBall-Games" size="large"
       onAction="RibbonControl.ToggleonAction"
       getPressed="RibbonControl.buttonPressed"
       getLabel = "RibbonControl.buttonLabel"/>
     </group>
    </tab>
    </tabs>
    </ribbon>
    </customUI>




    Option Explicit
    Dim oRibbon As IRibbonUI
    Dim bMarkedDraft As Boolean
    
    'Callback for customUI.onLoad
    Sub OnRibbonLoad(ribbon As IRibbonUI)
        Dim x As Object
        Set oRibbon = ribbon
        On Error Resume Next
        Set x = Application.ActiveWindow.View.Slide.Shapes("Draftmaster")
        On Error GoTo 0
                
        bMarkedDraft = Not (x Is Nothing)
        oRibbon.Invalidate
    End Sub
    
    
    'Callback for customButton7 onAction
    Sub ToggleonAction(control As IRibbonControl, pressed As Boolean)
        Select Case control.Id
            Case Is = "customButton7"
                
                If Not bMarkedDraft Then
                    
                    Dim shp As Shape
                    Set shp = Application.ActiveWindow.View.Slide.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=39.118086, Top:=5.6692878, Width:=26.362188, Height:=21.826758)
                    With shp
                        .Fill.Visible = msoFalse
                        .Line.Visible = msoFalse
                        .Name = "Draftmaster"
                        
                        With .TextFrame
                            .TextRange.Text = "Draft"
                            .VerticalAnchor = msoAnchorTop
                            .MarginBottom = "3.685037"
                            .MarginLeft = "0"
                            .MarginRight = "0"
                            .MarginTop = "3.685037"
                            .WordWrap = msoFalse
                        
                            With .TextRange
                                .Font.Size = 12
                                .Font.Name = "Arial"
                                .Font.Color.RGB = RGB(89, 171, 244)
                                .ParagraphFormat.Alignment = ppAlignLeft
                            End With
                        End With
                    End With
            
                Else
                    
                    Application.ActiveWindow.View.Slide.Shapes("Draftmaster").Delete
                End If
        End Select
        
        bMarkedDraft = Not bMarkedDraft
        oRibbon.Invalidate
    End Sub
    
    
    'Callback for customButton7 getPressed
    Sub buttonPressed(control As IRibbonControl, ByRef returnedVal)
        Select Case control.Id
            Case Is = "customButton7"
                returnedVal = bMarkedDraft
        End Select
        oRibbon.Invalidate
    End Sub
    
    
    'Callback for customButton7 getLabel
    Sub buttonLabel(control As IRibbonControl, ByRef returnedVal)
        Select Case control.Id
            Case Is = "customButton7"
                If bMarkedDraft Then
                    returnedVal = "Clear DRAFT"
                Else
                    returnedVal = "Mark DRAFT"
                End If
        End Select
    End Sub

    Play with the attachment (probably not perfect, but it'll show you the idea)
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    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

  3. #3
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location
    Thank you, Paul.

    At the moment I feel quite helpless. Your tool worked (and gave me an error message, when I deleted the stamp manually). Then I copied the code into my own document, debugging was fine - and once again PPT told me "Macro not running". How can a macro run in one document, but not in second one?

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,787
    Location
    Did you update the XML?
    ---------------------------------------------------------------------------------------------------------------------

    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
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location
    Yes, that was the first thing I did. The only thing I changed was the icon. But as my icon appears, that should not be the reason. I tried three times now, twice with blank documents, but it is always the same. Strange, isn't it?

  6. #6
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location
    The macro-not-running message appears twice when I open up the presentation, twice when I choose the RG tab and again whenever I press the button.

    I started deleting parts, tyring to find out a bit per exclusion. First I deleted the whole VBA code and still all six messages appeared. For the last two that's logical, as there is no macro anymore, but I take this as a hint, that the problem is part of the XML code.

    After deleting "onLoad="RibbonControl.OnRibbonLoad"" the first two messages didn't appear any longer. I don't know whether this information helps anyway or not ... and still it doesn't give a hint, why the macro works in Paul's presentation ...

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,787
    Location
    The XML onLoad = .... calls the OnRibbonLoad sub to store the ribbon object and do a little init




    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="RibbonControl.OnRibbonLoad" > 
    <ribbon> 
    <tabs> 
    <tab id="RGHomeTab" label="RG Home"> 
    <group id="ToggleTest" label="Test"> 
    <toggleButton id="customButton7" image="CuteBall-Games" size="large" 
    onAction="RibbonControl.ToggleonAction" 
    getPressed="RibbonControl.buttonPressed" 
    getLabel = "RibbonControl.buttonLabel"/> 
    </group> 
    </tab> 
    </tabs> 
    </ribbon> 
    </customUI>

     'Callback for customUI.onLoad
    Sub OnRibbonLoad(ribbon As IRibbonUI) 
        Dim x As Object 
        Set oRibbon = ribbon 
        On Error Resume Next 
        Set x = Application.ActiveWindow.View.Slide.Shapes("Draftmaster") 
        On Error GoTo 0 
         
        bMarkedDraft = Not (x Is Nothing) 
        oRibbon.Invalidate 
    End Sub

    Go to Options, Advanced, General section and check "Show User Interface Errors" to see what's happening
    Attached Images Attached Images
    ---------------------------------------------------------------------------------------------------------------------

    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

  8. #8
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location
    Where can I see it? What I did:
    1. Opened a blank presentation, saved it, closed it.
    2. Reopened it, went to options, added the checkmark on "Show add-in user interface errors", saved, closed.
    3. Opened the UI editor, chose the presentation, chose 2007, pasted in your XML code from 11:42, deleted the Bs and Us, 'til it was valid, changed the icon. saved, closed.
    4. Opened the presentation - and as before, the message macro not running appeared twice, when I opened, and twice, when I chose the RG tab to look, if the icon is there. It is.
    5. Went to the developer tab, opened a module, pasted in your VBA code from 11:42, deleted the Bs and Us from the first line, went to debugging (no reaction), went back to RG tab, clicked my button and reveived: Macro not running.

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,787
    Location
    Open a blank presentation

    Insert a standard module and insert the vba from my example

    Add the checkmark on "Show add-in user interface errors" is needed

    Save as a PPTM file

    Close Powerpoint

    Open the UI editor, chose the presentation, chose 2007, paste in my XML code. Probably have to change the image="CuteBall-Games" to something else

    Save

    Open the PPTM again and see

    If that doesn't work, then check your Trust Center settings

    If that doesn't work post the PPTM and I'll look at it for you

    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    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

  10. #10
    I made this its own thread, but the xml link in your code currently references a reference that has been removed. I cannot seem to find where the new link is either.

  11. #11
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,787
    Location
    I made this its own thread, but the xml link in your code currently references a reference that has been removed. I cannot seem to find where the new link is either.



    The formatting tags got added when I pasted.

    It's only the onLoad= callback that you need to add


    <customUI xmlns=http://schemas.microsoft.com/office/2006/01/customui onLoad="RibbonControl.OnRibbonLoad" >

    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    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

  12. #12
    The namespace is the link I was talking about. The namespace web address not existing is fine as this is just a name for the xml code, and doesn't actually reference the things in that web address.

  13. #13
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location
    Paul.pptm

    Hi Paul,

    here it comes - still no changes. My security options for macros are at the lowest level.

    But please don't invest too much time in it. As John already taught me how to solve my original problem with two buttons, this is only on top. It shouldn't damage your weekend. ;-)

  14. #14
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,787
    Location
    in the XML when you use the module_name-dot-macro_name like this ...

    onLoad="RibbonControl.OnRibbonLoad"

    ... the module name need to be RibbonControl


    Change the module name in [Properties]

    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    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

  15. #15
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location
    Wow! Small changes having big impact!

    So otherwise I could, e.g., keep the name "Module1" but replace "RibbonControl" with "Module1" in VBA- and XML-code, wherever it appears?

    Thank you for your patience!

  16. #16
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,787
    Location
    Don't you just hate it
    when computers do
    what you tell them to do
    and not what you
    want them to do??
    ---------------------------------------------------------------------------------------------------------------------

    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

  17. #17
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location
    So true ...

Posting Permissions

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