VBA、Excel 2010、在新选项卡中打开 Internet Explorer
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17386091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA, Excel 2010, open internet explore in new tab
提问by awsmitty
I have searched, tried various parameters, flags switches. No luck
我已经搜索过,尝试过各种参数,标志开关。没运气
Here's what I'm trying to do. I have a spreadsheet that has various company names. It has VBA code that when clicked on the company name, the macro opens the financials for that company on Google finance or yahoo finance, ... but, it always open on a new window. For comparison purposes, it would be a lot more useful if all of this were on different tabs of the same window.
这就是我想要做的。我有一个包含各种公司名称的电子表格。它有 VBA 代码,当点击公司名称时,宏会在谷歌金融或雅虎金融上打开该公司的财务,但是,它总是在新窗口上打开。出于比较的目的,如果所有这些都在同一窗口的不同选项卡上,那将会更有用。
Is there any way to change the code so that when a company name is clicked on, that web page opens on a new tab of an already open iexplorer. I am using VBA, excel 2010, Win7
有什么方法可以更改代码,以便在单击公司名称时,该网页会在已打开的 iexplorer 的新选项卡上打开。我正在使用 VBA、excel 2010、Win7
回答by David Zemens
Assuming that IE
is an object variable representing an instance of InternetExplorer.Application
:
假设这IE
是一个表示 实例的对象变量InternetExplorer.Application
:
Sub TestNewTabInIE()
' modified from code originally found at:
'http://www.ozgrid.com/forum/showthread.php?t=174692
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
While .ReadyState <> 4 'READYSTATE_COMPLETE
DoEvents
Wend
'# Navigate to one URL
.Navigate "http://google.com"
'# Navigate to another URL, in a new tab.
.Navigate "Http://yahoo.com", CLng(2048)
End With
End Sub
Sometimes it is hard to find answers if you don't know what question to ask. I find the answer using this google query:
有时,如果您不知道该问什么问题,就很难找到答案。我使用这个谷歌查询找到答案:
https://www.google.com/search?q=VBA+explorer+new+tab
https://www.google.com/search?q=VBA+explorer+new+tab
I always make sure my query has "VBA" in it, and a few words describing what I'm trying to do. It is usually also helpful to include relevant methods or properties (e.g., "VBA explorer .Navigate new tab" might be similarly useful). I have found that the results matching these terms tend to be more precise/complete.
我总是确保我的查询中包含“VBA”,以及描述我正在尝试做的事情的几句话。包含相关方法或属性通常也很有帮助(例如,“VBA explorer .Navigate new tab”可能同样有用)。我发现匹配这些术语的结果往往更精确/完整。
It was the #2 result:
这是#2结果: