Do any of you have a code I can use to control the printer from Excel? I probably need an API call together with some code. I have searched Internet and this forum, but can't find anything.
MK - Norway
Do any of you have a code I can use to control the printer from Excel? I probably need an API call together with some code. I have searched Internet and this forum, but can't find anything.
MK - Norway
From J. Walkenbach's Excel 2003 Power Programming. Great book. This will get you started. I have not fooled with the printer settings at all. This code is supposed to retreive the default printer information. Maybe play around with it and see if you can use it as a base for what you need?
ActiveSheet.PageSetup.Orientation = xlLandscape
Private Declare Function GetProfileStringA Lib "kernel32" _ (ByVal lpAppName As String, ByVal lpKeyName As String, _ ByVal lpDefault As String, ByVal lpReturnedString As _ String, ByVal nSize As Long) As Long Sub DefaultPrinterInfo() Dim strLPT As String * 255 Dim Result As String Call GetProfileStringA("Windows", "Device", "", strLPT, 254) Result = Application.Trim(strLPT) ResultLength = Len(Result) Comma1 = InStr(1, Result, ",", 1) Comma2 = InStr(Comma1 + 1, Result, ",", 1) 'Gets printer’s name Printer = Left(Result, Comma1 - 1) 'Gets driver Driver = Mid(Result, Comma1 + 1, Comma2 - Comma1 - 1) 'Gets last part of device line Port = Right(Result, ResultLength - Comma2) 'Build message Msg = "Printer:" & Chr(9) & Printer & Chr(13) Msg = Msg & "Driver:" & Chr(9) & Driver & Chr(13) Msg = Msg & "Port:" & Chr(9) & Port 'Display message MsgBox Msg, vbInformation, "Default Printer Information" End Sub
Last edited by Tarball; 11-02-2007 at 01:02 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks