Vba 远程服务器计算机不存在或无法用于特定网站

Vba 远程服务器计算机不存在或无法用于特定网站,vba,internet-explorer,Vba,Internet Explorer,我尝试使用以下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

我尝试使用以下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
它为“谷歌”等网站工作

但当我试图打开像我的公司PLM“Agile()”这样的特定站点时,抛出了一个错误 “远程服务器计算机不存在或不可用”

我可以在资源管理器上打开网页,但从下面的行执行时抛出错误

Do Until .readyState = 4
    DoEvents
Loop  

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

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

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
参考:


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

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

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
参考:


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

我对此使用了早期绑定,并创建了对象InternetExplorerMedium,而不是InternetExplorer,它似乎可以工作。

我对此使用了早期绑定并创建了对象InternetExplorerMedium而不是InternetExplorer,它似乎可以工作。

问题是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或LocationName在窗口之间进行选择。

问题是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或LocationName在窗口之间进行选择。

谢谢您的回复,但我仍然面临相同的错误,即运行时错误462。如果可能,您可以尝试发布该URL吗?我们可以试着用它做一个测试来检查问题。除此之外,您可以尝试参考下面的链接以获取有关该错误的更多信息。谢谢你的回复,但我仍然面临同样的错误,运行时错误462。如果可能的话,你可以尝试发布该URL吗?我们可以试着用它做一个测试来检查问题。除此之外,您可以尝试参考下面的链接以获取有关该错误的更多信息。我也犯了同样的错误。我通常只使用VBA+IE进行非常快速的简单web抓取和/或如果需要与同事快速共享,等等。否则,我使用python+selenium。我想从我们的内部sharepoint/delve站点快速获取一些信息,但失败了,出现了错误462,正如您所说的。我前后直接查看了另一个网站,他们都成功了。我认为VPN/内部网络是问题的核心。我改用python+selenium!我也犯了同样的错误。我通常只使用VBA+IE进行非常快速的简单web抓取和/或如果需要与同事快速共享,等等。否则,我使用python+selenium。我想从我们的内部sharepoint/delve站点快速获取一些信息,但失败了,出现了错误462,正如您所说的。我前后直接查看了另一个网站,他们都成功了。我认为VPN/内部网络是问题的核心。我改用python+selenium!另一个相关问题另一个相关问题