PDA

View Full Version : [SOLVED] Something wrong in XML? Or in VBA? Or something missing anywhere?



RandomGerman
06-01-2015, 02:18 PM
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(msoTextOrienta tionHorizontal, 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

Paul_Hossler
06-01-2015, 06:07 PM
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(msoTextOrientationHor izontal, 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)

RandomGerman
06-02-2015, 12:46 AM
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?

Paul_Hossler
06-02-2015, 05:56 AM
Did you update the XML?

RandomGerman
06-02-2015, 09:07 AM
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?

RandomGerman
06-02-2015, 09:41 AM
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 ...

Paul_Hossler
06-02-2015, 12:42 PM
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

RandomGerman
06-02-2015, 01:01 PM
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.

Paul_Hossler
06-02-2015, 01:43 PM
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

13586

etheriault
06-03-2015, 11:36 AM
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.

Paul_Hossler
06-03-2015, 04:42 PM
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" >



13597

etheriault
06-04-2015, 06:18 AM
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.

RandomGerman
06-05-2015, 07:30 AM
13617

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. ;-)

Paul_Hossler
06-05-2015, 11:27 AM
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]

13621

RandomGerman
06-06-2015, 10:58 AM
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!

Paul_Hossler
06-08-2015, 04:14 PM
Don't you just hate it
when computers do
what you tell them to do
and not what you
want them to do??

RandomGerman
06-09-2015, 01:20 AM
So true ...