Search code examples
phpvbams-worddcomoffice-automation

Why does a VBA function does not work with PHP 7?


I just upgraded my web application to PHP 5.XXX to PHP 7.4.28.

I solved most of the issues so far, but I've been stuck on a VBA (DCOM) function that apparently is not recognized anymore:

$myTable->Range->InsertBreak(8);

Where "8" means wdColumnBreak.

Could you please let me know if there is any alternative syntax to make this column break work correctly?

Any suggestions is really appreciated, Thank you very much


Solution

  • After struggling for a while, I could find the following solution:

    $myNumber= new VARIANT(8, VT_I4);
    $MyTable->Range->InsertBreak($myNumber);
    

    Basically the parameter of the InsertBreak function must be treated as a variant, not as a numeric. With this syntax, it works just fine.

    I really wanted to share this solution because I don't like the approach "this technology is not recommended anymore, just go for the latest one"... It's not always so simple to migrate to new technologies (without even having any guarantee about their reliability).

    Cheers