Here it is an interesting article that well explain how to create word macros using powershell:
https://4sysops.com/archives/create-word-macros-with-powershell/
about Excel you can review this one:
https://4sysops.com/archives/excel-macros-with-powershell/