Come dovrebbe essere completato questo 'riadattamento' del tuo codice?
'=========================================================
Option Explicit
#If VBA7 And Win64 Then
Public Declare PtrSafe Function ShowWindow Lib "user32.dll" (ByVal hwnd As LongPtr, ByVal nCmdShow As LongPtr) As LongPtr
#Else
Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
#End If
Sub TimerDelay(Optional Delay As Double)
Const vDelay As Double = 0.25
Dim vTimer As Double
If Delay = 0 Then Delay = vDelay
vTimer = Timer
Do While Timer < vTimer + Delay: Loop
End Sub
Sub AccessoCassettoFiscale()
Dim Nominativo As String, Utente As String, Password As String, Pin As String, UtenzaDiLavoro As String
Dim AccediCassettoFiscale As Boolean
Nominativo = Worksheets("Codici").Range("B2")
Utente = Worksheets("Codici").Range("B3")
Password = Worksheets("Codici").Range("B4")
Pin = Worksheets("Codici").Range("B5")
UtenzaDiLavoro = Worksheets("Codici").Range("B6") 'SOGGETTO_INCARICANTE
'Dim iTimer: iTimer = Timer
Const iDelay As Double = 0.5 '1
Dim Window As Object
Dim IEApp As Object
Dim oElem As Object
Dim but As Object
Dim sTestoAvviso As String
Application.StatusBar = Nominativo & sTestoAvviso '": Caricamento dati web in corso. Attendere ..."
'<--- verifico se è già aperta una sessione di internet explorer e nel caso chiudo la finestra --->
On Error Resume Next
For Each Window In CreateObject("shell.application").Windows
If Window.Name = "Internet Explorer" Then Window.Quit
Next Window
On Error GoTo Errore
TimerDelay iDelay * 3
'<--- creo una nuova sessione di internet explorer e carico i dati per accedere a Fisconline/Entratel --->
Set IEApp = CreateObject("InternetExplorer.Application")
With IEApp
.Silent = True
'ShowWindow .hwnd, 3 'Finestra massimizzata
.navigate "
https://telematici.agenziaentrate.gov.it/Main/login.jsp"
Do Until .readyState = 4: TimerDelay iDelay: Loop
With .document
.all("nome_utente_ar").Value = Utente
.all("password_ar").Value = Password
.all("codicepin").Value = Pin
.all("logonForm").submit
Do Until .readyState = "complete": TimerDelay iDelay: Loop
On Error Resume Next
If UtenzaDiLavoro = "" Then
.all("sceltaDelegante").Value = Utente
Else
For Each oElem In .all("sceltaDelegante")
If oElem.InnerText = UtenzaDiLavoro Then
.all("sceltaDelegante").Value = oElem.Value
Exit For
End If
Next oElem
End If
Do Until .readyState = "complete": TimerDelay iDelay: Loop
.all("AssociazioneProfiloForm").submit
Do Until .readyState = "complete": TimerDelay iDelay: Loop
For Each oElem In .GetElementsByClassName("btn btn-primary")
If Trim(oElem.Inntertext) = "Ricordamelo in seguito" Then
oElem.Click
End If
Next oElem
Do Until .readyState = "complete": TimerDelay iDelay: Loop
On Error GoTo Errore
End With
'AccediCassettoFiscale
Do Until .readyState = 4: TimerDelay iDelay: Loop
.navigate "
https://telematici.agenziaentrate.gov.it/Servizi/consultazioneCassetto.jsp"
Do Until .readyState = 4: TimerDelay iDelay: Loop
With .document
Do Until .readyState = "complete": TimerDelay iDelay: Loop
For Each but In .GetElementsByClassName("btn btn-primary")
If Trim(but.InnerText) = "Cassetto Fiscale personale" Then
but.Click
Exit For
End If
Next but
Do Until .readyState = "complete": TimerDelay iDelay: Loop
End With
Do Until .readyState = 4: TimerDelay iDelay: Loop
ShowWindow .hwnd, 3 'Finestra massimizzata
End With
RiprendiErrore:
Set Window = Nothing
Set IEApp = Nothing
Set oElem = Nothing
Set but = Nothing
Application.StatusBar = False
'Debug.Print Timer - iTimer
Exit Sub
Errore:
Select Case Err.Number
Case -
2147023706
MsgBox "Errore n. " & Err.Number & vbNewLine & _
Err.Description & vbNewLine & _
"L'applicazione Internet Explorer non ha completato la chisura definitiva." & vbNewLine & _
"Attendere qualche secondo e riprovare l'accesso!", _
vbCritical, "Errore Accesso"
Case Else
MsgBox "Si è verificato un errore imprevisto!" & vbNewLine & _
"Errore n. " & Err.Number & vbNewLine & _
Err.Description, vbCritical, "Errore VBA imprevisto"
End Select
Resume RiprendiErrore
End Sub
'=================================================
...1000 grazie, Maurizio