在隐藏模块中编译错误:模块1

我在VBA中有一个Addin for Excel-2010。 如果我从VBA编辑器执行代码,它工作正常。 但是,当我使用为Addin生成的function区中的button执行macros时,会引发此错误: 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 

使用自定义用户界面编辑器生成的代码:

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

您在callbackEnd Sub时错过了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 

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

您启动Word或Excel时收到“编译隐藏模块中的错误”错误信息

在Excel中编译错误