Opening Printer Proprties with space in the printer name.
This code opens a specified printer's Printer Properties. It works if there are no spaces in the printer name: if the printer is named TestThisPrinter, it works. If it is named "Test This Printer" it does not. I get a message that says "Printing preferences cannot be displayed. Double check the printer name and make sure that the printer is connected to the network.
I suppose I could remove the spaces from the printer names to be tested, but I really would not like to do that. Does anyone have any idea how I can get this to work with spaces in the printer name?
I am using TestComplete 7.52 (Yes, I know it is old) in Windows 10.
Thanks.
sub Test1
Call OpenPrinterProperties("Test This Printer")
end sub
sub OpenPrinterProperties(PRName)
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("rundll32 printui.dll,PrintUIEntry /e /n\\" & Sys.HostName & "\" & PRName)
end sub
Hi Rlent,
TestComplete 7.52 and Windows 10 are already strange combination :) TestComplete 7.52 doesn’t officially supports the latest Windows version. So, everything you do on this computer you are doing at your own risk – we cannot guarantee that TestComplete 7 will work fine.
As for your question, when there are spaces in a path, you need to put the text into quotes to pass it as a parameter, like "Test This Printer". So, modify the execution line something like this:
Set oExec = WshShell.Exec("rundll32 printui.dll,PrintUIEntry /e /n" & "'" & "\\" & Sys.HostName & "\" & PRName & "'")
That didn't work for me, but it pointed me in the righ direction. What did work for me was:
Set oExec = WshShell.Exec("rundll32 printui.dll,PrintUIEntry /e /n" & Chr(34) & "\\" & Sys.HostName & "\" & PRName & Chr(34))
Thanks!