【问题标题】:Compile Error in Hidden Module: Module 1隐藏模块中的编译错误:模块 1
【发布时间】:2015-03-12 11:30:46
【问题描述】:

我在 VBA 中有一个用于 Excel-2010 的插件。如果我从 VBA 编辑器执行代码,它工作正常。但是当我使用为插件生成的功能区中的按钮执行宏时,它会引发此错误:Compile Error in Hidden Module: Module 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

使用自定义 UI 编辑器生成的代码:

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

【问题讨论】:

    标签: vba excel ribbonx


    【解决方案1】:

    您在回调结束时缺少End Sub - 您只有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
    

    【讨论】:

    • @EugeneAstafiev 不,不是。所有例程都必须以End Sub 结尾,而不是End
    • 是的,你是对的 - Sub Statement。 Visual Basic 和 VBA 之间是有区别的。
    • 这就是问题所在。非常感谢@Rory !!
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 2012-11-19
    • 1970-01-01
    • 2021-08-29
    • 2012-11-21
    • 2013-11-08
    相关资源
    最近更新 更多