Solved

Word 2010 ActivePrinter property case sensitive

Posted on 2011-02-11
1
2,873 Views
Last Modified: 2012-05-11
Hi,

We use VBA macro's in Word to change the printer before printing a document.

     Application.ActivePrinter = "\\server\printer"

This code has worked since WordXP however in Word 2010 the server part became case sensitive. Therefore the following will work ...
     Application.ActivePrinter = "\\server\printer"
but this will not work
     Application.ActivePrinter = "\\Server\printer"
resulting in Error 5216

To make things worse on the same Windows 2003 network, the case changes from pc to pc so the code will work on one computer but the case needs te be different on another.



0
Comment
Question by:dataconsult01
1 Comment
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
Comment Utility
You could look for the printer name with the expected capitalisation with this function.
Function GetPrinter(strMyCasePrinter As String) As String
    Dim WshNetwork As Object
    Dim Printers As Object
    Dim printer As Variant
    Set WshNetwork = CreateObject("WScript.Network")
    Set Printers = WshNetwork.EnumPrinterConnections
    For Each printer In Printers
        If UCase$(strMyCasePrinter) = UCase$(printer) Then
            GetPrinter = printer
            Exit For
        End If
    Next
End Function

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now