{"id":66,"date":"2012-02-15T08:04:43","date_gmt":"2012-02-15T07:04:43","guid":{"rendered":"http:\/\/teske.dk\/?p=66"},"modified":"2012-02-15T08:12:43","modified_gmt":"2012-02-15T07:12:43","slug":"print-to-special-printer-in-backgroud-without-changing-default-printer","status":"publish","type":"post","link":"http:\/\/teske.dk\/?p=66","title":{"rendered":"Print to special printer in background, without changing default printer"},"content":{"rendered":"<p>Have you ever wanted to print to another printer than the default in Lotus Notes via LotusScript.<\/p>\n<p>If you do that in windows, windows will remember that printer the next time you print in Lotus Notes.<\/p>\n<p>This could be a problem if you have an Application that prints to a specific printer (ex. Labels).<br \/>\nBut if you want to print ex. a mail shortly there after, you don&#8217;t want it to use that printer.<\/p>\n<p>It all resets if you restart Lotus Notes, but that not an option. Its a windows problem, and not something Lotus Notes can do anything about.<\/p>\n<p>But i have found some code that prints, and sets the printer back to the original again.<\/p>\n<p>Credit goes to Michael R. Barrick.<\/p>\n<p>Here is the code for a button and a class that you can use if you have this problem.<\/p>\n<p>Button:<\/p>\n<p>Use &#8220;lib.dmc.print&#8221;<\/p>\n<p>Sub Click(Source As Button)<br \/>\n\tDim printing As New Printing()<br \/>\n\tCall printing.PrintDoc()<br \/>\nEnd Sub<\/p>\n<p>Class:<br \/>\n%REM<br \/>\n\tLibrary lib.dmc.print<br \/>\n\tCreated Sep 21, 2011 by Thomas Lindberg &#8211; T175260\/Laan-Spar<br \/>\n\tDescription: Comments for Library<br \/>\n%END REM<br \/>\nOption Public<br \/>\nOption Declare<\/p>\n<p>Declare Function GetProfileString Lib &#8220;kernel32&#8221; Alias &#8220;GetProfileStringA&#8221; (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long<\/p>\n<p>%REM<br \/>\n\tClass Printing<br \/>\n\tDescription: Comments for Class<br \/>\n%END REM<br \/>\nClass Printing<\/p>\n<p>\tPublic Function PrintDoc()<\/p>\n<p>\t\tDim WshNetwork As Variant<br \/>\n\t\tDim WshPrinters As Variant<br \/>\n\t\tDim pArray() As String<br \/>\n\t\tDim strBuffer As String * 254<br \/>\n\t\tDim iRetValue As Long<br \/>\n\t\tDim DefaultPrinter As String<br \/>\n\t\tDim pCount As Integer<br \/>\n\t\tDim n As Integer<br \/>\n\t\tDim PrinterPath As Variant<br \/>\n\t\tDim ws As New NotesUIWorkspace<\/p>\n<p>\t\t&#8216; Retreive current default printer information<br \/>\n\t\tiRetValue = GetProfileString(&#8220;windows&#8221;, &#8220;device&#8221;, &#8220;,,,&#8221;, strBuffer, 254)<br \/>\n\t\tDefaultPrinter$ = Left(strBuffer, InStr(strBuffer, &#8220;,&#8221;) &#8211; 1)<br \/>\n\t\tPrint &#8220;Current default printer is &#8221; &#038; DefaultPrinter$<\/p>\n<p>\t\tSet WshNetwork = CreateObject(&#8220;WScript.Network&#8221;)<br \/>\n\t\tSet WshPrinters = WshNetwork.EnumPrinterConnections()<\/p>\n<p>\t\t&#8216;count the connected printers<br \/>\n\t\tpCount% = 0<br \/>\n\t\tFor n = 1 To WshPrinters.Count() Step 2<br \/>\n\t\t\tIf wshPrinters(n) <> &#8220;&#8221; Then pCount%=pCount%+1<br \/>\n\t\tNext<\/p>\n<p>\t\t&#8216;collect the names of the connected printers<br \/>\n\t\tReDim pArray(pCount%-1) As String<br \/>\n\t\tpCount% = 0<br \/>\n\t\tFor n = 1 To WshPrinters.Count() Step 2<br \/>\n\t\t\tIf wshPrinters(n) <> &#8220;&#8221; Then<br \/>\n\t\t\t\tpArray(pCount%) = wshPrinters(n)<br \/>\n\t\t\t\tpCount%=pCount%+1<br \/>\n\t\t\tEnd If<br \/>\n\t\tNext<\/p>\n<p>\t\tPrinterPath = ws.Prompt(4,&#8221;Select Printer&#8221;,&#8221;Choose a printer from the following list:&#8221;,&#8221;&#8221;,pArray)<br \/>\n\t\tIf CStr(PrinterPath)=&#8221;&#8221; Then Exit function<\/p>\n<p>\t\tWshNetwork.SetDefaultPrinter CStr(PrinterPath)<\/p>\n<p>\t\tPrint &#8220;Default printer is now &#8221; &#038; CStr(PrinterPath)<\/p>\n<p>\t\tDim uidoc As NotesUIDocument<br \/>\n\t\tSet uidoc = ws.CurrentDocument<br \/>\n\t\tCall uidoc.Print( 1, 0, 0, False, PrinterPath )<br \/>\n\t\tWshNetwork.SetDefaultPrinter DefaultPrinter$<br \/>\n\t\tPrint &#8220;Default printer restored to &#8221; &#038; DefaultPrinter$<\/p>\n<p>\t\tSet WshNetwork = Nothing<br \/>\n\t\tSet WshPrinters = Nothing<br \/>\n\tEnd function<\/p>\n<p>End Class<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever wanted to print to another printer than the default in Lotus Notes via LotusScript. If you do that in windows, windows will remember that printer the next time you print in Lotus Notes. This could be a &hellip; <a href=\"http:\/\/teske.dk\/?p=66\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[74,77],"tags":[3,24,26,4],"_links":{"self":[{"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/posts\/66"}],"collection":[{"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/teske.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=66"}],"version-history":[{"count":2,"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/posts\/66\/revisions"}],"predecessor-version":[{"id":69,"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/posts\/66\/revisions\/69"}],"wp:attachment":[{"href":"http:\/\/teske.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/teske.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/teske.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}