Log in

View Full Version : Break mode error messages interrupt loading of ribbon controls



neilt17
09-08-2017, 07:20 AM
I have created two addins each of which adds a group in the ribbon when PowerPoint is started. The groups contain context sensitive controls which become active when the appropriate object is active in a slide.

On one machine, when I open PowerPoint with the two addins enabled, every second or third time (it doesn't appear to be entirely consistent), the ribbon controls do not load properly - and I get message boxes popping up saying "PowerPoint can't start this feature because you currently have a Visual Basic for Applications project in break mode." (The message appears 8 times, the first add in ribbon group - Grid maker - appears after 3 error messages, the next one after two more error messages, then there are 3 more error messages to OK).

This occurs on one Windows 10 machine - with Office 2016 installed, it does not occur on a Windows 10 virtual machine with the same office set up. It occurs with earlier versions of the addin from 3 months ago, which weren't getting those errors at the time. It doesn't seem to occur when just one of the add-ins are enabled.

It may be that there is some other error on this machine which is causing this problem - however the OS is up to date, and I re-installed Office in case there was a problem - but this made no difference.

Any pointers to how I could actually be able to find the source of this problem would be great - the error messages aren't really helping, there is extensive error handling in the add-ins, but no error is being logged.


Ribbon XML Add-in 1:



<customUI onLoad="gmRibbonUI_onLoad" xmlns="[removed]" xmlns:nsCommtap="Commtap Namespace">
<ribbon startFromScratch="false">
<tabs>
<tab idMso="TabHome">
<group id="gridMakerGroup" label="Grid maker">
<button id="gmMakeGrid"
label="Make into grid"
imageMso="TableInsert"
size="normal"
onAction="makeGrid"
getEnabled="gm_GetEnabled" />
<button id="gmScaleSelection"
label="Scale"
imageMso="DrawingCanvasScale"
size="normal"
onAction="scaleSelection"
getEnabled="gm_GetEnabled" />
</group>
</tab>
<tab idQ="nsCommtap:CommtapTools" label="Commtap Tools">
<group id="CTgridMakerGroup" label="Grid maker">
<button id="CTgmMakeGrid"
label="Make into grid"
imageMso="TableInsert"
size="normal"
onAction="makeGrid"
getEnabled="gm_GetEnabled" />
<button id="CTgmScaleSelection"
label="Scale"
imageMso="DrawingCanvasScale"
size="normal"
onAction="scaleSelection"
getEnabled="gm_GetEnabled" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>


Ribbon XML for second addin



<customUI onLoad="csRibbonUI_onLoad" xmlns="[removed]" xmlns:nsCommtap="Commtap Namespace">
<ribbon startFromScratch="false">
<tabs>
<tab idMso="TabHome">
<group id="commtapSymboliserGroup" label="Commtap Symboliser">
<button id="csSymboliseForwards"
label="Symbolise"
imageMso="ClipArtInsert"
size="large"
onAction="SymboliseForwards"
getEnabled="cs_GetEnabled"
keytip="B"/>
<button id="csSymboliseBackwards"
label="Previous"
imageMso="MailMergeGoToPreviousRecord"
size="normal"
onAction="SymboliseBackwards"
getEnabled="cs_GetEnabled" />
<button id="csDefaultPictureSize"
label="Default size"
imageMso="PivotChartMultipleUnified"
size="normal"
onAction="defaultSymbolSize"
getEnabled="cs_GetEnabled" />
<button id="csSymboliserPreferences"
label="Preferences"
imageMso="OrgChartDataOptionsDisplay"
size="normal"
onAction="symboliserPreferences" />
</group>
</tab>
<tab idQ="nsCommtap:CommtapTools" label="Commtap Tools">
<!-- Use idQ when creating a tab shared between namespaces - which will be the same so that different add-ins can be on the same tab. -->
<group id="CTcommtapSymboliserGroup" label="Commtap Symboliser">
<button id="CTcsSymboliseForwards"
label="Symbolise"
imageMso="ClipArtInsert"
size="large"
onAction="SymboliseForwards"
getEnabled="cs_GetEnabled"
keytip="B"/>
<button id="CTcsSymboliseBackwards"
label="Previous"
imageMso="MailMergeGoToPreviousRecord"
size="normal"
onAction="SymboliseBackwards"
getEnabled="cs_GetEnabled" />
<button id="CTcsDefaultPictureSize"
label="Default size"
imageMso="PivotChartMultipleUnified"
size="normal"
onAction="defaultSymbolSize"
getEnabled="cs_GetEnabled" />
<button id="CTcsSymboliserPreferences"
label="Preferences"
imageMso="OrgChartDataOptionsDisplay"
size="normal"
onAction="symboliserPreferences" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>


Ribbon loading for first addin:



Option Explicit
Option Base 0


Dim m_oMyRibbon As IRibbonUI
Dim m_boolShapeSelected As Boolean
Dim m_oAppEvents As New CGMApplicationEvents


Private Const msMODULE As String = "GMApplicationEventsModule"


Function get_m_oMyRibbon() As IRibbonUI
Set get_m_oMyRibbon = m_oMyRibbon
End Function


Function set_m_boolShapeSelected(value As Boolean)
m_boolShapeSelected = value
End Function
Function get_m_boolShapeSelected() As Boolean
get_m_boolShapeSelected = m_boolShapeSelected
End Function


Sub gm_GetEnabled(control As IRibbonControl, ByRef returnedVal)


Const sSOURCE As String = "gm_GetEnabled"
On Error GoTo ErrorHandler

returnedVal = True

If control.Id = "gmMakeGrid" Or control.Id = "gmScaleSelection" Then
returnedVal = GMApplicationEventsModule.get_m_boolShapeSelected
End If
' For Commtap Tools tab:
If control.Id = "CTgmMakeGrid" Or control.Id = "CTgmScaleSelection" Then
returnedVal = GMApplicationEventsModule.get_m_boolShapeSelected
End If

ErrorExit:
Exit Sub

ErrorHandler:
If bCentralErrorHandler(msMODULE, sSOURCE, , True) Then
Stop
Resume
Else
Resume ErrorExit
End If
End Sub


Sub gmRibbonUI_onLoad(Ribbon As IRibbonUI)
Set m_oMyRibbon = Ribbon
End Sub


' Use Auto_Open for storing a reference to the application object
' instead of onLoad above.
Sub Auto_Open()
Set m_oAppEvents.App = Application
End Sub


CGMApplicationEventsClass:



Option Explicit
Option Base 0


Private Const msMODULE As String = "CGMApplicationEvents"


Public WithEvents App As Application


Private Sub App_WindowSelectionChange(ByVal Sel As Selection)


Const sSOURCE As String = "App_WindowSelectionChange"
On Error GoTo ErrorHandler


If Application.ActiveWindow.Selection.Type <> ppSelectionShapes Then
GMApplicationEventsModule.set_m_boolShapeSelected False
Else
GMApplicationEventsModule.set_m_boolShapeSelected True
End If

If Not GMApplicationEventsModule.get_m_oMyRibbon Is Nothing Then

Dim oRibbon As IRibbonUI
Set oRibbon = GMApplicationEventsModule.get_m_oMyRibbon

oRibbon.InvalidateControl "gmMakeGrid"
oRibbon.InvalidateControl "gmScaleSelection"

' In the Commtap Tools tab:
oRibbon.InvalidateControl "CTgmMakeGrid"
oRibbon.InvalidateControl "CTgmScaleSelection"
End If


ErrorExit:
Exit Sub

ErrorHandler:
If bCentralErrorHandler(msMODULE, sSOURCE, , True) Then
Stop
Resume
Else
Resume ErrorExit
End If


End Sub


Ribbon loading for second addin:



Option Explicit
Option Base 0


Public m_oAppEvents As CApplicationEvents
Private m_boolTextBoxSelected As Boolean
Private m_boolImageSelected As Boolean
Private m_oMyRibbon As IRibbonUI
Private Const msMODULE As String = "ApplicationEventsModule"


Sub csRibbonUI_onLoad(Ribbon As IRibbonUI)

Const sSOURCE As String = "csRibbonUI_onLoad"
On Error GoTo ErrorHandler

Set m_oMyRibbon = Ribbon

ErrorExit:
Exit Sub

ErrorHandler:
If bCentralErrorHandler(msMODULE, sSOURCE, , True) Then
Stop
Resume
Else
Resume ErrorExit
End If

End Sub


' Use Auto_Open for storing a reference to the application object
' instead of onLoad above.
Sub Auto_Open()

Const sSOURCE As String = "Auto_Open"
On Error GoTo ErrorHandler


If m_oAppEvents Is Nothing Then
Set m_oAppEvents = Factory.CreateCApplicationEvents
End If
Set m_oAppEvents.App = Application

ErrorExit:
Exit Sub

ErrorHandler:
If bCentralErrorHandler(msMODULE, sSOURCE, , True) Then
Stop
Resume
Else
Resume ErrorExit
End If

End Sub


Public Function get_m_oMyRibbon() As IRibbonUI


Const sSOURCE As String = "get_m_oMyRibbon"
On Error GoTo ErrorHandler


Set get_m_oMyRibbon = m_oMyRibbon

ErrorExit:
Exit Function

ErrorHandler:
If bCentralErrorHandler(msMODULE, sSOURCE, , True) Then
Stop
Resume
Else
Resume ErrorExit
End If

End Function


Public Function set_m_boolTextBoxSelected(value As Boolean)
m_boolTextBoxSelected = value
End Function
Public Function get_m_boolTextBoxSelected() As Boolean
get_m_boolTextBoxSelected = m_boolTextBoxSelected
'get_m_boolTextBoxSelected = True
End Function
Public Function set_m_boolImageSelected(value As Boolean)
m_boolImageSelected = value
End Function
Public Function get_m_boolImageSelected() As Boolean
get_m_boolImageSelected = m_boolImageSelected
'get_m_boolImageSelected = True
End Function


Sub cs_GetEnabled(Control As IRibbonControl, ByRef returnedVal)


returnedVal = True


Const sSOURCE As String = "cs_GetEnabled"
On Error GoTo ErrorHandler

logToFile Control.Id


' On the Home tab:
If Control.Id = "csSymboliseForwards" Or Control.Id = "csSymboliseBackwards" Then
returnedVal = ApplicationEventsModule.get_m_boolTextBoxSelected
ElseIf Control.Id = "csDefaultPictureSize" Then
returnedVal = ApplicationEventsModule.get_m_boolImageSelected
End If

' On the Commtap Tools tab:
If Control.Id = "CTcsSymboliseForwards" Or Control.Id = "CTcsSymboliseBackwards" Then
returnedVal = ApplicationEventsModule.get_m_boolTextBoxSelected
ElseIf Control.Id = "CTcsDefaultPictureSize" Then
returnedVal = ApplicationEventsModule.get_m_boolImageSelected
End If

ErrorExit:
Exit Sub

ErrorHandler:
If bCentralErrorHandler(msMODULE, sSOURCE, , True) Then
Stop
Resume
Else
Resume ErrorExit
End If


End Sub


CApplicationEvents class:



Option Explicit
Option Base 0


Public WithEvents App As Application
Private Const msMODULE As String = "CApplicationEvents"


Private Sub App_WindowSelectionChange(ByVal Sel As Selection)

Const sSOURCE As String = "App_WindowSelectionChange"
On Error GoTo ErrorHandler

If Application.ActiveWindow.Selection.Type <> ppSelectionText Then
ApplicationEventsModule.set_m_boolTextBoxSelected False
Else
ApplicationEventsModule.set_m_boolTextBoxSelected True
End If

If Application.ActiveWindow.Selection.Type <> ppSelectionShapes Then
ApplicationEventsModule.set_m_boolImageSelected False
Else
ApplicationEventsModule.set_m_boolImageSelected True
End If

If Not ApplicationEventsModule.get_m_oMyRibbon Is Nothing Then
Dim oRibbon As IRibbonUI
Set oRibbon = ApplicationEventsModule.get_m_oMyRibbon

' On the Home tab:
oRibbon.InvalidateControl "csSymboliseForwards"
oRibbon.InvalidateControl "csSymboliseBackwards"
oRibbon.InvalidateControl "csDefaultPictureSize"

' On the Commtap Tools tab:
oRibbon.InvalidateControl "CTcsSymboliseForwards"
oRibbon.InvalidateControl "CTcsSymboliseBackwards"
oRibbon.InvalidateControl "CTcsDefaultPictureSize"
End If


ErrorExit:
Exit Sub

ErrorHandler:
If bCentralErrorHandler(msMODULE, sSOURCE, , True) Then
Stop
Resume
Else
Resume ErrorExit
End If
End Sub

neilt17
09-10-2017, 05:46 AM
If the getEnabled parameter is removed from customUI.xml - then the error messages don't appear;
If the Auto_Open() sub is commented out - the error messages don't appear;
Calling "Stop" on the first line of Auto_Open(): the error messages appear *before* reaching this stop statement.

This then seems to suggest the error is encountered when PowerPoint is last closed, and somehow PowerPoint still retains this in its state when it has re-opened.

Note, I tried to reproduce the problem with a minimal version of the code above, but was unsuccesful. So the problem may be somehow being created elsewhere. But there is no information from PowerPoint as to where that might be, I just get the message "PowerPoint can't start this feature because you currently have a Visual Basic for Applications project in break mode.", without any further clues.

neilt17
09-10-2017, 11:37 AM
This might not be to do with my add-in:

My version of Office (2016) was 1707 - update 8326.2096, I reverted it to version 1705 (update 8201.2102) and the problem goes away.

I also noted this https://answers.microsoft.com/en-us/msoffice/forum/msoffice_powerpoint-mso_other-mso_365hp/powerpoint-error-message-powerpoint-cant-start/28f34895-5133-4676-8550-747e968a7e1d?auth=1&rtAction=1505060282020

neilt17
01-14-2019, 01:03 PM
This issue still crops up from time to time - and will also go away for no apparent reason - e.g. commenting out a piece of code and then finding the problem has gone away, but then uncommenting out that piece of code - and the problem not re-appearing (!) Anyway, I've posted the problem on msdn (with new information): https://social.msdn.microsoft.com/Forums/en-US/e3226183-de21-43cf-944c-32fc97410f52/break-mode-error-messages-when-loading-ribbon-controls-on-powerpoint-start-up

Paul_Hossler
01-14-2019, 04:39 PM
One thing to try ...

Word and Excel have a 'Code Cleaner' that exports all modules as text, deletes them, and then imports them

http://www.appspro.com/Utilities/CodeCleaner.htm




During the process of creating VBA programs a lot of junk code builds up in your files. If you don't clean your files periodically you will begin to experience strange problems caused by this extra baggage. Cleaning a project involves exporting the contents of all its VBComponents to text files, deleting the components and then importing the components back from the text files.



You can do the same process manually (export, delete, import) with your powerpoint and see if it gets rid of intermittent errors


During the process of creating VBA programs a lot of junk code builds up in your files. If you don't clean your files periodically you will begin to experience strange problems caused by this extra baggage. Cleaning a project involves exporting the contents of all its VBComponents to text files, deleting the components and then importing the components back from the text files.

neilt17
01-14-2019, 10:18 PM
I use a version of the code cleaner adapted for PowerPoint: http://www.tushar-mehta.com/powerpoint/vba_codecleaner/index.htm - unfortunately that doesn't solve the problem when it occurs.

neilt17
01-29-2019, 08:28 PM
I have now posted an updated version of this question on stackoverflow: https://stackoverflow.com/questions/54432885/periodically-getting-vba-break-mode-error-messages-when-loading-ribbon-controls