Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Sandro,
Grazie mille
Prova a sostituire il codice precedente con la seguente versione e fammi vedere l'eventuale messaggio che riscontri:
'=========>>
Option Explicit
'--------->>
Public Sub Stampa2Stampanti()
Dim WB As Workbook
Dim SH As Worksheet
Dim sStampante As String
Dim vVar As Variant
Const sFoglioDaStampare = "Foglio2" '<<=== Modifica
Const sStampantePDF = "pdf"
Set WB = ThisWorkbook
Set SH = WB.Sheets(sFoglioDaStampare)
With Application
sStampante = .ActivePrinter
vVar = GetPrinter(sStampantePDF)
On Error GoTo XIT
.ActivePrinter = vVar
SH.PrintOut
.ActivePrinter = sStampante
SH.PrintOut
End With
XIT:
MsgBox vVar
End Sub
'--------->>
Public Function GetPrinter(ByVal PrinterName As String) As String
Dim arrDevices As Variant
Dim Device As Variant
Dim Devices As Variant
Dim sPrinter As String
Dim RegObj As Object
Dim RegValue As String
Const HKEY_CURRENT_USER = &H80000001
Const sdevices As String = _
"Software\Microsoft\Windows NT\CurrentVersion\Devices"
Set RegObj = GetObject("winmgmts:{impersonationLevel=impersonate}!\." _
& "root\default:StdRegProv")
RegObj.EnumValues HKEY_CURRENT_USER, sdevices, _
Devices, arrDevices
For Each Device In Devices
RegObj.GetStringValue HKEY_CURRENT_USER, _
sdevices, Device, RegValue
sPrinter = Device & " on " & Split(RegValue, ",")(1)
If InStr(1, sPrinter, PrinterName, vbTextCompare) > 0 Then
GetPrinter = sPrinter
Exit Function
End If
Next
Set RegObj = Nothing
End Function
'<<=========
===
Regards,
Norman