我有一张工作表,其中包含加载用户表单的 Workbook_Open 代码。
关闭表单和工作簿后,Excel 提示我输入 VBA 项目密码。
我在此页面上找到了有关此问题的一些信息:
http://support.microsoft.com/kb/280454
http://social.msdn.microsoft.com/Forums/office/en-US/8cb79e54-26ae-487c-8945-69b84b2e4eeb/com-addins-and-vba-password-prompt-bug
但这似乎是 COM 插件的问题,我有一些。 问题是加载项不是我的,我无法更改或禁用它们。
还有其他解决办法吗?
对我来说,问题不在于某些插件或未发布的参考资料。这就是 Dropbox 徽章。一旦我删除它,当我关闭 Excel 时,就不再要求输入密码了。要禁用 Dropbox Badge,请打开 Dropbox 应用,转到“设置”,然后转到“偏好设置”,然后在“常规”选项卡中选择 Dropbox Badge 下的“从不显示”。 我在以下论坛找到了这个解决方案: https://www.excelforum.com/excel-programming-vba-macros/1100960-ever-annoying-vba-password-prompt-at-close-of-excel-2.html
当您有指向对象的悬挂指针时,就会发生这种情况。 对于您在 VBA 中执行的每个“Set xyz=”,请确保您有一个相应的“Set xyz=Nothing”。 对于指向 COM 对象或从 COM 对象获取的任何内容也是如此。 确保关闭所有 ADO 连接等。 要特别小心地处理所有错误,以便在工作簿关闭之前将所有对象变量设置为 Nothing,大致如下:
Option Explicit
Option Compare Text
Public Sub Refresh()
On Error GoTo FAIL
Set wb = ThisWorkbook
wb.Activate
' do something useful
DONE:
On Error GoTo 0
Set wb = Nothing
Exit Sub
FAIL:
MsgBox Err.Description
GoTo DONE
End Sub
我有很多工作簿,一些用户也遇到了同样的问题。我们完成了检查 COM 加载项以及 Windows 和 Office 的各种组合的过程。
最后,我们将以下代码作为 workbook_beforeclose 事件的一部分包含在内,并为我们的用户解决了问题。
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim intResponse as Integer
'If the workbook needs to be saved then ask the user if they want to save the workbook, if not then exit without saving
'Need a global boolean to ensure the request to save the workbook is not shown twice
If Not ThisWorkbook.Saved And Not blnStartedClose Then
blnStartedClose = True
intResponse = MsgBox("Do you want to Save the this Workbook" & vbNewLine & vbNewLine & _
"Select 'Yes' to save the workbook" & vbNewLine & _
"Select 'No' to close without saving", vbYesNo, "Confirm - Workbook Save?")
If intResponse = vbYes Then ThisWorkbook.Save
End If
'If the user has clicked on 'No' to save the workbook then reset the "Saved" property to TRUE so that when we exit this routine no attempt to save the workbook is made
ThisWorkbook.Saved = True
End Sub
我的一些客户遇到了这个问题,我终于在安装 BlueBeam Extreme 后开始遇到这个问题。我取消选中 COM 加载项中的 BluebeamOfficeAddIn,并且在关闭 .xlsm 文件时密码框不再弹出。我将进行更多挖掘,看看这是否是我的代码,但直到现在我才遇到这个问题,禁用该插件似乎有帮助......