首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Jacob禁用java代码中的VB6 MsgBox

如何使用Jacob禁用java代码中的VB6 MsgBox
EN

Stack Overflow用户
提问于 2013-03-24 15:17:43
回答 1查看 649关注 0票数 5

我正在使用雅各布API从VB宏调用一些Sub。我想阻止这个宏生成的MsgBox。

这是我打开宏XXXX.xls并运行包含一些MsgBox的子traiteOT的代码。

代码语言:javascript
复制
    `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");

            com.jacob.com.Variant f = new com.jacob.com.Variant(true);
        //  Dispatch.call(workBook, "Close", f);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            excel.invoke("Quit", new Variant[0]);
            ComThread.Release();
        }
    }

    public static void main(String[] args) {
        ExcelMacroTest emt = null;
        try {

            final File file = new File("D:XXXXXXXX.xls");
            final String macroName = "!TraiteOT";
            callExcelMacro(file, macroName);

        } finally {
            if (emt != null) {
                emt.quit();
            }
        }
    }
}

`

EN

回答 1

Stack Overflow用户

发布于 2013-03-26 01:02:48

您不能阻止msgbox,除非您注释执行函数的代码,否则请避免以其他方式调用该代码。

如果确实有必要,您可以将VBA代码读取到一个变量中,剥离Msgbox函数调用,然后执行它(使用Visual Basic For Applications Extensibility)

最好只在工作簿中编写一个没有MsgBox的特殊函数

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15596091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档