Trigger VBA-Macros Application in Laravel

后端 未结 1 1059
傲寒
傲寒 2020-12-22 08:31

I have an excel file that has macro enabled VBA. It has a button that will trigger the VBA for my excel. I was just wondering if it is available to trigger a VBA in Laravel

相关标签:
1条回答
  • 2020-12-22 08:54

    Well as long as using Internet Explorer you can use JavaScript on your button to call a macro:

    <input type="button" value="Run My Macro" onclick="RunMacro("C:\MyFile.xlsm", "ThisIsMyMacro");">
    

    And using this function:

    <script type="text/javascript" language="javascript">
        function RunMacro(FileName, MacroName)
        {
        var ExApp;
    
        ExApp = new ActiveXObject("Excel.Application");
        ExApp.Workbooks.Open(FileName);
        ExApp.Run(MacroName);
        }
    </script>
    

    Then you need to wait until the macro is finished and trigger the upload event with JavaScript. Not sure about how we can detect that the macro has finished. Probably the easiest way would be to have one button to trigger the macro and then let the user click another button for uploading when the macro finished.


    Another solution could be having a link that opens the file and it runs a macro on the Workbook_Open() event: Open excel file through normal html link. So the user needs to click that link before he can use the upload button.

    0 讨论(0)
提交回复
热议问题