Hello

I have a workbook used by many People. Every user have a PDF-printer called PowelPDFPrinter installed on their PC, but the Ne-number is different. Therefore I have to get this number for correct printing.
I have a VBA code to do this as a part of a code:

sCurrentPrinter = Application.ActivePrinter ' to record the standard printer

Dim Arr As Variant
Dim Device As Variant
Dim Devices As Variant
Dim printer As String
Dim RegObj As Object
Dim RegValue As String
Const HKEY_CURRENT_USER = &H80000001

Set RegObj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
RegObj.enumvalues HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Devices", Devices, Arr

For Each Device In Devices
RegObj.getstringvalue HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Devices", Device, RegValue
printer = Device & " på " & Split(RegValue, ",")(1) & vbCrLf
If Device = "PowelPDFWriter" Then ' if Device = PowelPDFWriter, the correct printer is found, and printer = "PowelPDFWriter på Nexx:" (på is Norwegian for on)
Exit For
End If
Next


MsgBox printer

Application.ActivePrinter = printer


ExecuteExcel4Macro _
"PRINT(1,,,1,,,,,,,,2,""xUNC"",,TRUE,,FALSE)"

Application.ActivePrinter = sCurrentPrinter ' to reset to standard printer


Everything works fine, except this line:
Application.ActivePrinter = printer

where I get a Run-time error 1004: Method 'ActivePrinter' of object'_Application' failed.

MsgBox Returns correct name for the printer

Anywhone who knows why the Application.ActivePrinter statement fail?

regards,