Trigger VBA-Macros Application in Laravel

丶灬走出姿态 提交于 2019-12-02 14:29: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 app. I have like an upload button in laravel but when i click it, it will first trigger the button in excel that triggers the VBA then it will read the upload excel function. Do you think it is possible? And how?


回答1:


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.



来源:https://stackoverflow.com/questions/49684820/trigger-vba-macros-application-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!