I agree that authoring a single select per CustomerID in the key file is wasteful and there is no need for the vbs script in this case. This also sounded like a one-off sort of request, so I thought I would offer a method that did not use a linked server.
Run the following query, either through the command line as in the article or in Query Analyzer and set your output options to create the desired output file.
SET NOCOUNT ON
dbo.Customers AS C
INNER JOIN dbo.Orders AS O ON C.CustomerID = O.CustomerID
INNER JOIN OPENDATASOURCE(
'Data Source=c:\;Extended Properties="text;HDR=No;FMT=Delimited"'
)...custID#txt AS T ON T.F1 = C.CustomerID
Some things of note;
• The Data Source is the directory where the file being read is
• If there are no Header Rows (HDR=No) the column names are F1, F2, F3 and so on.