Search code examples
vbaexcelribbonx

Compile Error in Hidden Module: Module 1


I've an Addin for Excel-2010 in VBA. If I execute the code from the VBA editor it works fine. But when I execute the macro using the button in the Ribbon generated for the Addin it throws this error: Compile Error in Hidden Module: Module 1

My code:

Sub QE_eventhandler(control As IRibbonControl)
    If MsgBox("Esta acción no se podrá deshacer. ¿Desea Continuar?", vbExclamation + vbOKCancel, "Confirmar -Quitar Espacios-") = vbOK Then
        QuitaEspacios
    End If
End

Sub QuitaEspacios()
Dim celda As Range
    For Each celda In Selection
        If TypeName(celda.Value) = "String" Then
            celda.Value = Application.WorksheetFunction.Trim(celda.Value)
        End If
    Next
 End Sub

The code generated with the Custom UI Editor:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon>
        <tabs>
            <tab id="customTab" label="GARSA Tools">
                <group id="customGroup1" label="Reformateo Texto">
                    <button id="customButton3" label="Quitar Espacios" size="large" onAction="QE_eventhandler" imageMso="TextEffectTracking" />
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

Solution

  • You are missing an End Sub at the end of the callback - you just have End:

    Sub QE_eventhandler(control As IRibbonControl)
        If MsgBox("Esta acción no se podrá deshacer. ¿Desea Continuar?", vbExclamation + vbOKCancel, "Confirmar -Quitar Espacios-") = vbOK Then
            QuitaEspacios
        End If
    End Sub