Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Default Printer aftamath77 Excel Discussion (Misc queries) 2 November 26th 08 05:37 PM
members on my network printer not able to print to default printer smeheut Excel Discussion (Misc queries) 0 June 18th 07 06:42 PM
Default Printer carlito_1985 Excel Programming 1 June 27th 05 08:27 AM
Default printer peterG Excel Programming 2 January 15th 04 06:06 PM
default printer solo_razor[_21_] Excel Programming 1 October 30th 03 03:22 PM


All times are GMT +1. The time now is 04:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"