Obtenez la fenêtre de IE objet par le titre de la fenêtre à l'aide de VBA

J'ai trouvé cette solution fournie par @mkingston:
Comment intercepter et de manipuler un Internet Explorer popup avec VBA

...mais il ne fonctionne pas pour moi. J'ai ajouté les deux bibliothèques de référence en question, mais quand je lance le script que je tombe sur ces questions:

Erreur de compilation: non défini Sous en raison de pauseUntilIEReady (depuis ce Sous n'était pas inclus avec la réponse, je le supprime à partir du script)

Erreur de compilation: Argument pas une option en raison de oGetIEWindowFromTitle (j'ai donc essayé commeting à obtenir le script pour compiler)

Après le script finalement compile, il obtiens cette erreur:

Erreur Automation
Le système ne peut pas trouver le fichier spécifié.

sur cette ligne de code:
Pour Chaque oGetIEWindowFromTitle Dans objShellWindows

Voici le code que j'essaie de l'exécuter:

Function oGetIEWindowFromTitle(sTitle As String, _
Optional bCaseSensitive As Boolean = False, _
Optional bExact As Boolean = False) As SHDocVw.InternetExplorer
Dim objShellWindows As New SHDocVw.ShellWindows
Dim found As Boolean
Dim startTime As Single
found = False
'Loop through shell windows
For Each oGetIEWindowFromTitle In objShellWindows
found = oGetIEWindowFromTitleHandler(oGetIEWindowFromTitle, sTitle, bCaseSensitive, bExact)
If found Then Exit For
Next
'Check whether a window was found
If Not found Then
Set oGetIEWindowFromTitle = Nothing
Else
'COMMENTED OUT TO GET SCRIPT TO COMPILE pauseUntilIEReady oGetIEWindowFromTitle
End If
End Function
Private Function oGetIEWindowFromTitleHandler(win As SHDocVw.InternetExplorer, _
sTitle As String, _
bCaseSensitive As Boolean, _
bExact As Boolean) As Boolean
oGetIEWindowFromTitleHandler = False
On Error GoTo handler
'If the document is of type HTMLDocument, it is an IE window
If TypeName(win.Document) = "HTMLDocument" Then
'Check whether the title contains the passed title
If bExact Then
If (win.Document.title = sTitle) Or ((Not bCaseSensitive) And (LCase(sTitle) = LCase(win.Document.title))) Then oGetIEWindowFromTitleHandler = True
Else
If InStr(1, win.Document.title, sTitle) Or ((Not bCaseSensitive) And (InStr(1, LCase(win.Document.title), LCase(sTitle), vbTextCompare) <> 0)) Then oGetIEWindowFromTitleHandler = True
End If
End If
handler:
'We assume here that if an error is raised it's because
'the window is not of the correct type. Therefore we
'simply ignore it and carry on.
End Function

et

Sub test()
Dim ie As SHDocVw.InternetExplorer
Dim doc As HTMLDocument 'If you have a reference to the HTML Object Library
'Dim doc as Object 'If you do not have a reference to the HTML Object Library
' Change the title here as required
Set ie = oGetIEWindowFromTitle("My popup window")
Set doc = ie.Document
Debug.Print doc.getElementsByTagName("body").Item(0).innerText
End Sub
  • Poste le code que vous essayez d'utiliser.
  • Salut Tim, je n'ai pas poster le code d'abord parce que c'est la même proposé dans la solution. J'ai copié ci-dessous avec une ligne en commentaire que j'ai eu à commenter pour obtenir le code à compiler.
InformationsquelleAutor icfireball | 2013-12-18