对于特定网站,远程服务器计算机不存在或不可用



我尝试使用以下VBA代码打开网站:

Dim IE As Object
Dim doc As Object
Dim strURL As String
Set IE = CreateObject("InternetExplorer.Application")
With IE '
    .Visible = True
    .navigate "https://Google.com"
    Do Until .readyState = 4
        DoEvents
    Loop

它在" Google"等网站上工作。

但是,当我尝试像我的公司PLM这样的特定网站时"远程服务器计算机不存在或不可用"

我可以在Explorer上打开网页,但是从下线执行时会抛出错误

Do Until .readyState = 4
    DoEvents
Loop  

这是由于对站点的任何保护吗?

我在此上使用了早期绑定,并创建了Internet Extplorermedium而不是Internet Explorer,并且它似乎有效。

问题是Internet Explorer与VBA断开连接(在我的情况下,一些内部安全设置)。解决方案是将Internet Explorer重新连接到VBA:

在行IE不再响应之后,包括此代码,现有的Internet Explorer窗口将分配给= ieObject1

    Dim shellWins As SHDocVw.ShellWindows
    Dim explorer As SHDocVw.InternetExplorer
    
    Set shellWins = New SHDocVw.ShellWindows
    
    For Each explorer In shellWins
        If explorer.Name = "Internet Explorer" Then
            Set IEObject1 = explorer
            Debug.Print explorer.LocationURL
            Debug.Print explorer.LocationName
        End If
    Next
    
    Set shellWins = Nothing
    Set explorer = Nothing

如果您打开了几个IE窗口,则此代码选择最后一个。如果需要几个打开的窗口,则可以使用URL或位置名称在窗口之间进行选择。

尝试使用下面的示例代码进行测试可能会帮助您解决问题。

Sub Automate_IE_Load_Page()
'This will load a webpage in IE
    Dim i As Long
    Dim URL As String
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
    'Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
    'Set IE.Visible = True to make IE visible, or False for IE to run in the background
    IE.Visible = True
    'Define URL
    URL = "https://agileplm.xxxx.com/Agile/default/login-cms.jsp"
    'Navigate to URL
    IE.Navigate URL
    ' Statusbar let's user know website is loading
    Application.StatusBar = URL & " is loading. Please wait..."
    ' Wait while IE loading...
    'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
    Do While IE.ReadyState = 4: DoEvents: Loop   'Do While
    Do Until IE.ReadyState = 4: DoEvents: Loop   'Do Until
    'Webpage Loaded
    Application.StatusBar = URL & " Loaded"
    'Unload IE
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing
End Sub

参考:

使用VBA

自动化Internet Explorer(IE)

如果您的问题持续存在,而不是尝试提供详细信息,无论您是打开页面问题还是在检查就绪的IE状态时出现错误。我们将尝试提供进一步的建议。

Dim IE As Object
Dim doc As Object
Dim strURL As String
Set IE = CreateObject("InternetExplorer.Application")
With IE
    .Visible = True
    .navigate "https://Google.com"
End With
For Each win In CreateObject("Shell.Application").Windows
    If win.Name Like "*Internet Explorer" Then
         Set IE = win: Exit For
    End If
Next
With IE
    Do Until .readyState = 4
        DoEvents
    Loop

相关内容

最新更新