Trigger VBA-Macros Application in Laravel

2019-03-05 22:50发布

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条回答
该账号已被封号
2楼-- · 2019-03-05 23:32

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.

查看更多
登录 后发表回答