|I have never heard of using command line switches to select specific sheets in a workbook for printing. I'm not saying it can't be done, but I don't know how you would pass the variable (the switch) to the application from DOS. |
As a possible workaround, if you put the code below into the ThisWorkbook module of a different workbook, it would to tell Excel to print specific sheets from another workbook.
For example, if you put this code in the ThisWorkbook module of C:\MyPrintCode.xls, and then entered C:\MyPrintCode.xls as a command line entry, it would print pages 1 and 3 of C:\TheBookToPrint.xls. That way you wouldn't have to put any code into the workbook that the server generates.
In this case, the workbook name and sheets to print are hardcoded, but the code could present dialog boxes and get that information from the user each time.
Private Sub Workbook_Open()
Application.Visible = False
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Note: If you want to open the workbook with this code to work on it, you have to stop the code executing the Application.Quit line. One way to do this to rename or move TheBookToPrint.xls. When the code tries to open TheBookToPrint.xls, it won't find it and will pop up an error. At that point you could stop the code and work on the file.
Hope that helps some...