如何从vb宏取消保护我的VB项目?我找到了这段代码:
Sub UnprotectVBProject(ByRef WB As Workbook, ByVal Password As String)
Dim VBProj As Object
Set VBProj = WB.VBProject
Application.ScreenUpdating = False
'Ne peut procéder si le projet est non-protégé.
If VBProj.Protection <> 1 Then Exit Sub
Set Application.VBE.ActiveVBProject = VBProj
'Utilisation de "SendKeys" Pour envoyer le mot de passe.
SendKeys Password & "~"
SendKeys "~"
'MsgBox "Après Mot de passe"
Application.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute
Application.Wait (Now + TimeValue("0:00:1"))
End Sub
Run Code Online (Sandbox Code Playgroud)
但是此解决方案不适用于Excel 2007.它在我的IDE中显示验证的窗口和打印密码.
然后,我的目标是取消保护我的VBproject而不显示此窗口.
谢谢你的帮助.
我正在使用JACOB API从VB宏调用一些Sub.我想阻止这个宏生成的MsgBox.
这是我打开宏XXXX.xls并运行包含一些MsgBox的子traiteOT的代码.
`private static void callExcelMacro(File file, String macroName) {
ComThread.InitSTA();
final ActiveXComponent excel = new ActiveXComponent("Excel.Application");
try {
// This will open the excel if the property is set to true
excel.setProperty("Visible", new Variant(true));
final Dispatch workbooks = excel.getProperty("Workbooks").toDispatch();
//String eventSink = null ;
Dispatch.call(workbooks,"Add");
Dispatch workBook = Dispatch.call(workbooks,"Open", file.getAbsolutePath()).toDispatch();
ExcelEventHandler w = new ExcelEventHandler();
Variant V1=new Variant(file.getName() + macroName);
// Calls the macro
final Variant result = Dispatch.call(excel, "Run", V1 );
// Saves and closes
//Dispatch.call(workBook, "Save"); …Run Code Online (Sandbox Code Playgroud)