Public Declare Function GetProfileString Lib "kernel32" _ 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 DefaultPrinter() As String Dim strReturn As String Dim intReturn As Integer strReturn = Space(255) intReturn = GetProfileString("Windows", ByVal "device", "", _ strReturn, Len(strReturn)) If intReturn Then strReturn = UCase(Left(strReturn, InStr(strReturn, ",") - 1)) End If DefaultPrinter = strReturn End Function
AutoCAD, AutoCAD Architecture (ACA/ADT), Revit Architecture, Revit MEP, Revit Structure, BIM, CAD, AutoLISP, VBA, VB, VB.NET, C#, databases, Access, SQL Server, FlexNet (FLEXlm), license usage reporting, software design, development, customization, integration...
Tuesday, January 10, 2006
Get the name of the default printer using VBA
Here is one way
Subscribe to:
Post Comments (Atom)
Some of the latest blog posts
Contact Us
| About JTB World |
Website General Terms of Use |
Privacy Policy
^ Top of page
© 2004- JTB World. All rights reserved.
Restored comment
ReplyDeleteby Anonymous
Works like a charm! Thanks!
Works with no problems.
ReplyDeleteDo you have code for setting default printer using VBA
In for example Excel VBA you can use Application.ActivePrinter
ReplyDeleteYou can also use WScript object in VBA like this:
Dim objPrinter
Set objPrinter = CreateObject("WScript.Network")
objPrinter.SetDefaultPrinter "\\ServerName\PrinterName"