![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I am trying to print a document to a specific network printer in DTS using an ActiveX VB script. I found the code below in another group, however, I'm getting a compile error when I try executing it, and I'm unsure why. (Expected End of Statement on Line 14) JoeO:"You use printer collection to select your desired printer as long as that printer is in the user's system printer collection. Dim X As Printer For Each X In Printers If X.DeviceName = "MyTargetPrinter" Then ' Set printer as system default. Set Printer = X ' Stop looking for a printer. Exit For End If Next 'Then print to X " -- End JoeO extract This is the full code: Function Main() Main = DTSTaskExecResult_Success ' DECLARATIONS: Dim XLPrinter as Printer Dim XLApp Dim XLWkb Dim XLWkSht 'SET VARIABLES: Set XLApp = CreateObject("Excel.Application") XLWkb = "C:\SQLData\MSSQL\JOBS\reports\SoftSeatPlanningRep ortBAK.xls" XLWkSht = "Shock Blocker Monthly Report" xlapp.visible = true 'PROCESS (PRINT) WORKSHEET: For Each XLPrinter In Printers If XLPrinter.DeviceName = "AcctPrinter" Then ' Set printer as system default. Set Printer = "AcctPrinter" ' Stop looking for a printer. Exit For End If Next xlapp.workbooks.open XLWkb xlapp.activeworkbook.worksheets(XLWkSht).printout 'CLOSE AND EXIT: xlapp.ActiveWorkbook.Saved = True xlapp.ActiveWorkbook.Close xlapp.quit End Function Thanks! Leslie |
#3
| |||
| |||
|
|
isn't it that ' DECLARATIONS: Dim XLPrinter as Printer you should comment out the as printer "Leslie" <Leslie (AT) discussions (DOT) microsoft.com> wrote in message news:32EDB38E-3CB7-43DF-8E19-D04B46B756D2 (AT) microsoft (DOT) com... I am trying to print a document to a specific network printer in DTS using an ActiveX VB script. I found the code below in another group, however, I'm getting a compile error when I try executing it, and I'm unsure why. (Expected End of Statement on Line 14) JoeO:"You use printer collection to select your desired printer as long as that printer is in the user's system printer collection. Dim X As Printer For Each X In Printers If X.DeviceName = "MyTargetPrinter" Then ' Set printer as system default. Set Printer = X ' Stop looking for a printer. Exit For End If Next 'Then print to X " -- End JoeO extract This is the full code: Function Main() Main = DTSTaskExecResult_Success ' DECLARATIONS: Dim XLPrinter as Printer Dim XLApp Dim XLWkb Dim XLWkSht 'SET VARIABLES: Set XLApp = CreateObject("Excel.Application") XLWkb = "C:\SQLData\MSSQL\JOBS\reports\SoftSeatPlanningRep ortBAK.xls" XLWkSht = "Shock Blocker Monthly Report" xlapp.visible = true 'PROCESS (PRINT) WORKSHEET: For Each XLPrinter In Printers If XLPrinter.DeviceName = "AcctPrinter" Then ' Set printer as system default. Set Printer = "AcctPrinter" ' Stop looking for a printer. Exit For End If Next xlapp.workbooks.open XLWkb xlapp.activeworkbook.worksheets(XLWkSht).printout 'CLOSE AND EXIT: xlapp.ActiveWorkbook.Saved = True xlapp.ActiveWorkbook.Close xlapp.quit End Function Thanks! Leslie |
![]() |
| Thread Tools | |
| Display Modes | |
| |