Mình có 2 đoạn Sub để bắt Object Internet Explorer như sau:
Không hiểu sao sub CloseIE thì chạy được bình thường còn sub unhideIE thì nó báo lỗi "Invalid procedure call or argument" ở ngay đoạn "If .Windows(i).Name = "Internet Explorer"". Kính nhờ mọi người giải thích giúp mình đoạn này với.
Thêm nữa, tại sao lệnh CreateObject("Shell.Application").Windows("Internet Explorer") lại không chạy được vậy ạ
PHP:
Sub CloseIE()
Dim i As Integer
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
On Error Resume Next
With CreateObject("Shell.Application")
For i = 0 To .Windows.Count - 1
If .Windows(i).Name = "Internet Explorer" Then Set oBrowser = .Windows(i)
Next
End With
On Error GoTo 0
If oBrowser Is Nothing Then Exit Sub
oBrowser.Quit
Set oBrowser = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
PHP:
Sub unhideIE()
Dim i As Integer
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
On Error Resume Next
With CreateObject("Shell.Application")
For i = 0 To .Windows.Count - 1
If .Windows(i).Name = "Internet Explorer" Then
If .Windows(i).Visible Then
.Windows(i).Visible = False
Else
.Windows(i).Visible = True
End If
Sheet8.CommandButton2.Caption = .Windows(i).Visible
End If
Next
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
Không hiểu sao sub CloseIE thì chạy được bình thường còn sub unhideIE thì nó báo lỗi "Invalid procedure call or argument" ở ngay đoạn "If .Windows(i).Name = "Internet Explorer"". Kính nhờ mọi người giải thích giúp mình đoạn này với.
Thêm nữa, tại sao lệnh CreateObject("Shell.Application").Windows("Internet Explorer") lại không chạy được vậy ạ
