Calling the Windows Deafult Printer

S

Simon Peers

How can I set the Windows Default Printer?

I am trying to set the printer back to the default printer after getting it
to print to a specific printer.

Does anyone know the specific code to do this?

I am calling this from Access but it is still basic code, here is hwat I
have tried:

'Print Invoice to PDF File
With xlSheet.PageSetup

xlSheet.Application.ActivePrinter = "CutePDF Writer on CPW2:"
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"CutePDF Writer on CPW2:", Collate:=True

With xlSheet.PageSetup
xlSheet.Application.ActivePrinter = "WindowsDefaultPrinter" = True
End With

The first bit works perfectly, captures the printer (PDF writer in this
case) and I need to be able to reset it back to the Windows Default Printer
as I I will not know what this printer is called.

xlSheet.Application.ActivePrinter = "***WindowsDefaultPrinter***" = True

The text between the stars gives errors not surprisingly, If this was
correct I think it would work.


Many thanks
 
L

Leith Ross

Hello Simon,

I posted this yesterday, but no problem to post it again. This works
for Excel and should work in Access also. Since the both use the same
caommand to set the printer.

EXAMPLE:
Application.ActivePrinter = GetDeafultPrinter


Code:
--------------------
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top