我正在做一个需要AddIn的用户应用程序,我想在workbook_open事件中更新它。
这是我的计划:
应该在vbProject受密码保护和隐藏的情况下完成所有操作。这是我的代码:
Private Sub Workbook_Open()
Dim wb As Workbook
Set wb = Thisworkbook
'
If common_DB.AddFSOref(wb) Then Debug.Print "Added Extensibility"
If common_DB.AddRegEx(wb) Then Debug.Print "Added Regular Expressions"
UpdateDBAddin
End Sub
这是我的更新代码,无需密码保护即可工作,但是在vbProject密码中添加引用时是必需的。我想抑制这一点,因为我的用户不必为此担心。
Public Sub UpdateDBAddin()
Dim UserPath As String
Dim AI As AddIn
Dim AddinSourcePath As String
Dim AddinName As String
Dim Addintitle As String
Dim RefName As String
Dim ref As Reference
RefName = "Ex_Ample_Name"
AddinName = "ExampleName.xlam"
Addintitle = "Example AddIn"
UserPath = Application.UserLibraryPath
AddinSourcePath = "E:\Xample\Path\"
Application.DisplayAlerts = False
For Each ref In Thisworkbook.VBProject.References
If ref.Name = RefName Then
Thisworkbook.VBProject.References.remove ref
End If
Next ref
If Application.AddIns(Addintitle).IsOpen Then
Workbooks(AddinName).Close False
End If
If common_DB.IsFile(UserPath & "\" & AddinName) Then
Application.AddIns(Addintitle).Installed = False
Kill (UserPath & "\" & AddinName)
End If
Application.AddIns.Add (AddinSourcePath & AddinName)
Application.AddIns(Addintitle).Installed = True
Application.DisplayAlerts = True
' Here the VBProject Password is requested from the user, I want to suppress that
Thisworkbook.VBProject.References.AddFromFile (UserPath & "\" & AddinName)
End Sub
问题:当我想向Vbproject添加新引用时如何隐藏密码?
EDIT1:困境,因为它仅在隐藏项目时发生,而我无法在保持模式下“调试”。我将问题缩小到在UpdateAddin的最后一行添加对addin的引用。
EDIT2 :这有一些有趣的行为。如果您只是取消密码提示,它就可以正常工作。因此,添加了参考。不管您输入密码还是取消密码都可以执行该行。