- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 VBA 代码来调用需要使用 OAuth2 进行身份验证的 protected API。一旦我尝试打开一个 URL,我就会被重定向到 ADFS 页面进行身份验证,然后我会回来。
现在对于某些使用 CreateObject("InternetExplorer.Application")
和 .Navigate URL
的应用程序可以正常工作,对于其他网络应用程序我需要使用 New InternetExplorerMedium
以使代码正常工作。
您能告诉我这些对象之间的区别吗?为什么有些网站使用一个对象而有些网站使用另一个对象?
谢谢
最佳答案
这种引用对象的方式称为“早期”和“后期绑定(bind)”。 From MSDN :
The Visual Basic compiler performs a process called binding when an object is assigned to an object variable.
An object is early bound when it is assigned to a variable declared to be of a specific object type. Early bound objects allow the compiler to allocate memory and perform other optimizations before an application executes.
By contrast, an object is late bound when it is assigned to a variable declared to be of type Object. Objects of this type can hold references to any object, but lack many of the advantages of early-bound objects.
You should use early-bound objects whenever possible, because they allow the compiler to make important optimizations that yield more efficient applications. Early-bound objects are significantly faster than late-bound objects and make your code easier to read and maintain by stating exactly what kind of objects are being used.
TL DR:
不同之处在于,在早期绑定(bind)中,您可以获得智能感知和编译时间奖励,但您应该确保 你已经添加了相应的库。
Sub MyLateBinding()
Dim objExcelApp As Object
Dim strName As String
'Definition of variables and assigning object:
strName = "somename"
Set objExcelApp = GetObject(, "Excel.Application")
'A Is Nothing check:
If objExcelApp Is Nothing Then Set objExcelApp = CreateObject("Excel.Application")
'Doing something with the Excel Object
objExcelApp.Caption = strName
MsgBox strName
End Sub
首先确保从 VBE>Extras>Libraries 添加 MS Excel 16.0 Object Library:
Sub MyEarlyBinding()
Dim objExcelApp As New Excel.Application
Dim strName As String
'Definition of variables and assigning object:
strName = "somename"
'A IsNothing check:
If objExcelApp Is Nothing Then Set objExcelApp = CreateObject("Excel.Application")
'Doing something with the Excel Object
objExcelApp.Caption = strName
MsgBox strName
End Sub
相关文章:
关于vba - VBA 中的后期绑定(bind)与早期绑定(bind)——(CreateObject() 与 New),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50583705/
我正在为从 API 级别 8 到 14 的 android 开发一个应用程序。我正在尝试在早期版本中获得与 android 4(请参阅联系人应用程序)相同的快速滚动行为(右侧固定的时尚滚动条)边)。有
早期(编译期)优化 jvm的编译器可以分为三个编译器: 前端编译器:把*.java转变为*.class的过程。如sun的javac、eclipse jdt中的增量式编译器(ecj)
苹果终于推出了所谓的auto-renewable subscriptions昨天。由于我在应用内购买方面的经验很少(仅限沙盒),所以我不确定我在这里是否一切顺利。似乎需要对收据进行服务器端验证。找出订
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 要求代码的问题必须表明对正在解决的问题的最低理解。包括尝试的解决方案、它们为什么不起作用以及预期结果。另
在 Wagner 的“Effective C#”第 23 项中,他解释说 interface methods are not virtual...they are a declaration of a
我最近遵循了本指南 Installing a Git Server using Apache (WebDAV) on Ubuntu Server 12.04使用 Apache (WebDAV) 设置本
这是我之前的问题 jQuery UI hiding not taking effect for early DOM elements 的后续问题。我几乎刚刚编辑了那个,但不想使 the accepte
我正在尝试替换 ZonedDateTime.toInstant方法,因为它仅从 API 26 for Android 开始可用。 但我的应用程序应该支持 API 19。 我想将 ZonedDateTi
我的电脑正确配置了 SSH,我在尝试克隆存储库时遇到了这个错误: 我运行这个命令来克隆存储库 git clone ssh://git-codecommit.us-west-2.amazonaws.co
我是一名优秀的程序员,十分优秀!