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