Forum Discussion

Victor_Sotnikov's avatar
Victor_Sotnikov
Copper Contributor
Aug 21, 2025

To call a VBA script from a T-SQL procedure

I have the following (unusual) task:

 

I need my T-SQL procedure to somehow call a VBA script. The VBA should copy all content of a certain sheet of an input Excel file into a certain sheet of an output Excel file.

The physical full path of the input Excel file is available only in the T-SQL procedure. Therefore, the procedure should somehow pass the file path into the VBA script.

How can I do that?

1 Reply

  • rodgerkong's avatar
    rodgerkong
    Iron Contributor

    I think you can write a powershell script, it recieves excel path as parameter. In the script, you can open excel and call vba functions. Then run the powershell script in SQL Server by call xp_cmdshell.

Resources