Can someone tell me how do I write code to print a specific spreadsheet rather than the whole workbook in excel from VB?
Here is what I got so far:
Dim EndWait 'As Double
Dim objApp 'As Excel.Application
Dim DailyFile 'As Workbook
Dim PrinterPath, WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
PrinterPath = "\\REGIONAL\NDPS-P36V-FIN-T620.FIN.MAB.MHS"
'WshNetwork.AddWindowsPrinterConnection(PrinterPath)
WshNetwork.SetDefaultPrinter PrinterPath
'WScript.Echo " New default printer is " & PrinterPath
'If MsgBox ("This program will print a spreadsheet by automating Microsoft Excel. OK to continue?", vbOkCancel) = vbCancel Then Wscript.Quit
Set objApp = CreateObject("Excel.Application"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
'''''''''' Remove the below line if you don't want to watch Excel
objApp.Visible = True
'''''''''' Replace the web page with the one you want printed.
'Set doc = wrd.Documents.Open("Set DailyFile = objApp.Workbooks.Open("I:\Daily Statistics Report\Daily Statistics.xls"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
'''''''''' This is a messy kluge to give the page time to load
'''''''''' If you try to print before the page is loaded, Word crashes!
EndWait = Now + (20 / 86400) ' 20 second delay to let page load
Do Until Now > EndWait
Loop
'''''''''' Un-comment the below line if you want to use a printer
'''''''''' other than your default. If you specify a printer,
'''''''''' it must be one that is already installed on your system.
'objApp.ActivePrinter = ".NDPS-IT-S2455.IT.MSS.MHS" ---> THIS DID NOT WORK
'objApp.ActivePrinter = "Lexmark Optra S 2455" ---> THIS DID NOT WORK
'objApp.ActivePrinter = "\\Regional\.NDPS-IT-S2455.IT.MSS.MHS" ---> THIS DID NOT WORK
DailyFile.printout
PrinterPath = "\\Regional\.NDPS-IT-T612.it.mss.mhs"
'WshNetwork.AddWindowsPrinterConnection(PrinterPath)
WshNetwork.SetDefaultPrinter PrinterPath
objApp.quit
'WScript.Echo " Printing has started. New default printer is " & PrinterPath
Set DailyFile = Nothing
Set objApp = Nothing
Set WshNetwork = Nothing
Here is what I got so far:
Dim EndWait 'As Double
Dim objApp 'As Excel.Application
Dim DailyFile 'As Workbook
Dim PrinterPath, WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network"
PrinterPath = "\\REGIONAL\NDPS-P36V-FIN-T620.FIN.MAB.MHS"
'WshNetwork.AddWindowsPrinterConnection(PrinterPath)
WshNetwork.SetDefaultPrinter PrinterPath
'WScript.Echo " New default printer is " & PrinterPath
'If MsgBox ("This program will print a spreadsheet by automating Microsoft Excel. OK to continue?", vbOkCancel) = vbCancel Then Wscript.Quit
Set objApp = CreateObject("Excel.Application"
'''''''''' Remove the below line if you don't want to watch Excel
objApp.Visible = True
'''''''''' Replace the web page with the one you want printed.
'Set doc = wrd.Documents.Open("Set DailyFile = objApp.Workbooks.Open("I:\Daily Statistics Report\Daily Statistics.xls"
'''''''''' This is a messy kluge to give the page time to load
'''''''''' If you try to print before the page is loaded, Word crashes!
EndWait = Now + (20 / 86400) ' 20 second delay to let page load
Do Until Now > EndWait
Loop
'''''''''' Un-comment the below line if you want to use a printer
'''''''''' other than your default. If you specify a printer,
'''''''''' it must be one that is already installed on your system.
'objApp.ActivePrinter = ".NDPS-IT-S2455.IT.MSS.MHS" ---> THIS DID NOT WORK
'objApp.ActivePrinter = "Lexmark Optra S 2455" ---> THIS DID NOT WORK
'objApp.ActivePrinter = "\\Regional\.NDPS-IT-S2455.IT.MSS.MHS" ---> THIS DID NOT WORK
DailyFile.printout
PrinterPath = "\\Regional\.NDPS-IT-T612.it.mss.mhs"
'WshNetwork.AddWindowsPrinterConnection(PrinterPath)
WshNetwork.SetDefaultPrinter PrinterPath
objApp.quit
'WScript.Echo " Printing has started. New default printer is " & PrinterPath
Set DailyFile = Nothing
Set objApp = Nothing
Set WshNetwork = Nothing