Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Finding the default printer
Hello,
Is there any way that I can specify that a selection should be printed to the default printer rather than the last printer that was used. Thank you in advance |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Finding the default printer
Hello Ben, I knew I had this code. I just didn't remember where I saved it. The macro returns the name of the default printer. Once you have that you can use VBA to the active printer to the default printer. EXAMPLE: P = GetDefaultPrinter Application.ActivePrinter = P Code: -------------------- '///////////////////////////////////////////' '/ /' '/ Get the Default Printer Information /' '/ For Windows '95, '98, ,Me ,NT, 2000, XP /' '/ /' '/ Written: October 23, 2005 /' '/ Author: Leith Ross /' '/ /' '///////////////////////////////////////////' '===================NOTE========================== ======= 'Windows Server 2003 and Windows XP/2000/NT: 'Calls to profile functions may be mapped to the 'registry instead of to the initialization files. 'This mapping occurs when the initialization file 'and section are specified in the registry under 'the following keys: 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\ ' CurrentVersion\IniFileMapping ' ' 'When the operation has been mapped, the GetProfileString 'function retrieves information from the registry, not 'from the initialization file; the change in the storage 'location has no effect on the function's behavior. '================================================= ======== Private Declare Function GetProfileString _ Lib "kernel32.dll" _ Alias "GetProfileStringA" _ (ByVal lpAppName As String, _ ByVal lpKeyName As String, _ ByVal lpDefault As String, _ ByVal lpReturnedString As String, _ ByVal nSize As Long) As Long Public Function GetDefaultPrinter() As String Dim Buffer As String Dim ByteCount As Long Dim MaxCount As Long Dim DefaultInfo As String MaxCount = 260 Buffer = String(MaxCount, Chr$(0)) 'Retreive current default printer information ByteCount = GetProfileString("windows", "device", ",,,", Buffer, MaxCount) DefaultInfo = Left(Buffer, ByteCount) 'Remove second item between commas and replace with "on" I = InStr(1, DefaultInfo, ",") LeftSide = Left(DefaultInfo, I - 1) I = InStr(I + 1, DefaultInfo, ",") RightSide = Right(DefaultInfo, ByteCount - I) DefaultInfo = LeftSide & " on " & RightSide GetDefaultPrinter = DefaultInfo End Function -------------------- Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=478631 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Default Printer | Excel Discussion (Misc queries) | |||
members on my network printer not able to print to default printer | Excel Discussion (Misc queries) | |||
Default Printer | Excel Programming | |||
Default printer | Excel Programming | |||
default printer | Excel Programming |