Is there any way to run a query on different servers using one code?

We are trying to create a job which runs a query on different servers and store the results in an Excel workbook on different sheets server wise. Is there any way how to connect different servers using just one code?