Vba 隐藏模块中的编译错误:模块1

Vba 隐藏模块中的编译错误:模块1,vba,excel,ribbonx,Vba,Excel,Ribbonx,我在VBA中有Excel-2010的加载项。如果我从VBA编辑器执行代码,它就可以正常工作。但是,当我使用为加载项生成的功能区中的按钮执行宏时,它会抛出以下错误:隐藏模块中的编译错误:模块1 我的代码: Sub QE_eventhandler(control As IRibbonControl) If MsgBox("Esta acción no se podrá deshacer. ¿Desea Continuar?", vbExclamation + vbOKCancel, "Con

我在VBA中有Excel-2010的加载项。如果我从VBA编辑器执行代码,它就可以正常工作。但是,当我使用为加载项生成的功能区中的按钮执行宏时,它会抛出以下错误:
隐藏模块中的编译错误:模块1

我的代码:

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
<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>
使用自定义UI编辑器生成的代码:

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

您在回调结束时缺少一个
结束子节点
-您只有
结束

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

查看以下描述类似问题的链接:


@EugeneAstafiev不,不是。所有例程必须以
end Sub
结束,而不是
end
结束。是的,你说得对。VisualBasic和VBA之间存在差异,这就是问题所在。非常感谢@Rory!!