We are faced with the same problem that you talked about when we need to modify Excel workbooks but donโt want to affect existing macros.
To do this, we used the LibXL library, and since version 3.3.1 it supports saving macros for .xls files. It is not written in PHP, so we wrote a little C ++ program, and then we call this program from php using the exec() method of PHP. It works very well.
source share