Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Excel VBA在IE中打开和导航_Vba_Internet Explorer_Excel - Fatal编程技术网

使用Excel VBA在IE中打开和导航

使用Excel VBA在IE中打开和导航,vba,internet-explorer,excel,Vba,Internet Explorer,Excel,我正在运行64位excel,我需要打开32位IE,以便java在我导航到的页面上运行(我在工作中这样做有一些特定的限制)。我一辈子都想不出如何让它发挥作用 我已经尝试了我在搜索中找到的所有代码,但似乎没有任何东西对我有效。当我运行下面的代码时,我得到了一个错误 activex组件无法创建对象“错误:设置 objShellWindows=objShell.Windows AppURL=”http://www.stackoverflow.com" AppToRun=“iexplore-nomerge

我正在运行64位excel,我需要打开32位IE,以便java在我导航到的页面上运行(我在工作中这样做有一些特定的限制)。我一辈子都想不出如何让它发挥作用

我已经尝试了我在搜索中找到的所有代码,但似乎没有任何东西对我有效。当我运行下面的代码时,我得到了一个错误

activex组件无法创建对象“错误:设置 objShellWindows=objShell.Windows

AppURL=”http://www.stackoverflow.com"
AppToRun=“iexplore-nomerge”
AboutBlankTitle=“空白页”
LoadingMessage=“正在加载堆栈溢出…”
ErrorMessage=“加载stackoverflow时出错。请用空白页关闭Internet Explorer,然后重试。如果问题仍然存在,请与IT部门联系。”
emptyttle=“”
“将Internet Explorer作为最小化窗口在单独的过程中启动,这样我们就不会看到工具栏消失
昏暗的地狱
设置WshShell=CreateObject(“WScript.Shell”)
WshShell。运行AppToRun,6
昏暗的奥布舍尔
昏暗的窗户
设置objShell=CreateObject(“Shell.Application”)
设置objShellWindows=objShell.Windows
昏昏欲睡
i开始=错误
模糊误差
错误=False
暗秒
秒=0
而(未启动)和(未启动错误)和(秒<30)
如果(不是objShellWindows什么都不是)那么
昏暗的奥布杰
暗淡的
“对于每个IE对象
对于objShellWindows中的每个objIE
如果(不是什么都不是)那么
如果是IsObject(对象文档),则
Set IE=objIE.Document
'对于不是activex控件的每个IE对象
如果变量类型(IE)=8,则
如果IE.Title=清空,则
如果Err.Number=0,则
即写加载消息
objIE.Toolbar=0
objIE.StatusBar=1
objIE.Navigate2 AppURL
i开始=正确
其他的
'要查看错误回复上的完整错误注释,请单击第1行的下一步
MsgBox错误消息
呃,明白了
ieError=True
退出
如果结束
如果结束
如果结束
如果结束
如果结束
设置IE=无
设置对象=无
下一个
如果结束
WScript.sleep 1000
秒=秒+1
温德
设置objShellWindows=Nothing
Set objShell=Nothing
'激活IE窗口并将其还原
success=WshShell.AppActivate(AboutBlankTitle)
如果成功的话
WshShell.SendKeys“%r”还原
如果结束

um,为什么不使用
Set Ie=CreateObject(“InternetExplorer.Application”)
?尝试早期绑定。从工具>引用中添加Internet explorer的引用并享受IntelliSense。Siddharth-最初我这样做时,它打开的是64位版本的IE,而不是32位版本-我需要能够控制我打开的IE版本。
AppURL = "http://www.stackoverflow.com"
AppToRun = "iexplore -nomerge"
AboutBlankTitle = "Blank Page"
LoadingMessage = "Loading stackoverflow..."
ErrorMessage = "An error occurred while loading stackoverflow.  Please close the Internet Explorer with Blank Page and try again.  If the problem continues please contact IT."
EmptyTitle = ""

'Launch Internet Explorer in a separate process as a minimized window so we don't see the toolbars disappearing
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run AppToRun, 6

Dim objShell
Dim objShellWindows

Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows

Dim ieStarted
ieStarted = False

Dim ieError
ieError = False

Dim seconds
seconds = 0

While (Not ieStarted) And (Not ieError) And (seconds < 30)

    If (Not objShellWindows Is Nothing) Then
        Dim objIE
        Dim IE

        'For each IE object
        For Each objIE In objShellWindows

            If (Not objIE Is Nothing) Then

                If IsObject(objIE.Document) Then
                    Set IE = objIE.Document

                    'For each IE object that isn't an activex control
                    If VarType(IE) = 8 Then

                        If IE.Title = EmptyTitle Then
                            If Err.Number = 0 Then
                                IE.Write LoadingMessage

                                objIE.Toolbar = 0
                                objIE.StatusBar = 1
                                objIE.Navigate2 AppURL

                                ieStarted = True
                            Else
                                'To see the full error comment out On Error Resume Next on line 1
                                MsgBox ErrorMessage
                                Err.Clear

                                ieError = True

                                Exit For
                            End If
                        End If
                    End If
                End If
            End If

            Set IE = Nothing
            Set objIE = Nothing
        Next
    End If

    WScript.sleep 1000
    seconds = seconds + 1
Wend

Set objShellWindows = Nothing
Set objShell = Nothing

'Activate the IE window and restore it
success = WshShell.AppActivate(AboutBlankTitle)

If success Then
    WshShell.SendKeys "% r"  'restore
End If