Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

【转载】VBA–早期和后期绑定声明

时 间:2023-03-14 09:58:32
作 者:金宇   ID:43  城市:江阴
摘 要:VBA早期和后期绑定声明
正 文:

我决定提供几个从早期绑定到后期绑定的示例,反之亦然,并为早期绑定提供必要的VBA参考库…
这些应该是了解哪些早期绑定声明需要哪些参考库的很好的起点,同时也有助于任何想要向任一方向转换的人。
我希望这对你们中的一些人有所帮助!
以下是迄今为止提供的示例:

Microsoft Access XX.X Object Library

EARLY BINDING LATE BINDING
REFERENCE Microsoft Access XX.X Object Library
(msacc.olb)
EXAMPLE Dim oAccess As Access.Application


Set oAccess = New Access.Application

Dim oAccess As Object


Set oAccess = CreateObject(“Access.Application”)

 

Microsoft ActiveX Data Object X.X Library

EARLY BINDING LATE BINDING
REFERENCE Microsoft ActiveX Data Object X.X Library
(msadoXX.dll)
EXAMPLE
CONNECTION
Dim oADODBConnection As ADODB.Connection


Set oADODBConnection = New ADODB.Connection

Dim oADODBConnection As Object


Set oADODBConnection = CreateObject(“ADODB.Connection”)

EXAMPLE
STREAM
Dim oADODBStream As ADODB.Stream


Set oADODBStream = New ADODB.Stream

Dim oADODBStream As Object


Set oADODBStream = CreateObject(“ADODB.Stream”)

 

Microsoft ADO Ext. X.X for DDL and Security Object Library

EARLY BINDING LATE BINDING
REFERENCE Microsoft ADO Ext. X.X for DDL and Security Object Library
(msadox.dll)
EXAMPLE
CATALOG
Dim oCat As ADOX.Catalog


Set oCat = New ADOX.Catalog

Dim oCat As Object


Set oCat = CreateObject(“ADOX.Catalog”)

 

Microsoft DAO 3.6 Object Library

This is a special case as there can be 2 distinct Libraries used here depending on the targetted database!

EARLY BINDING LATE BINDING
REFERENCE Microsoft DAO X.X Object Library (older mdb)
(daoXXX.dll)
or
Microsoft Office XX.X Access database engine Object Library (newer accdb & mdb)
(acedao.dll ???)
EXAMPLE Dim oDAO As DAO.DBEngine


Set oDAO = New DAO.DBEngine

Dim oDAO As Object


On Error Resume Next
Set oDAO = CreateObject(“DAO.DBEngine.120”)
If oDAO Is Nothing Then
Set oDAO = CreateObject(“DAO.DBEngine.36”)
If oDAO Is Nothing Then
Set oDAO = CreateObject(“DAO.DBEngine.35”)
End If
End If

On Error Goto 0
If oDAO Is Nothing Then Exit Sub ‘Function

 

Microsoft Excel XX.X Object Library

EARLY BINDING LATE BINDING
REFERENCE Microsoft Excel XX.X Object Library
(excel.exe)
EXAMPLE Dim oExcel As Excel.Application


Set oExcel = New Excel.Application

Dim oExcel As Object


Set oExcel = CreateObject(“Excel.Application”)

 

Microsoft Internet Controls

EARLY BINDING LATE BINDING
REFERENCE Microsoft Internet Controls
(ieframe.dll)
EXAMPLE
INTERNET EXPLORER
Dim oIE As SHDocVw.InternetExplorer


Set oIE = New SHDocVw.InternetExplorer

Dim oIE As Object


Set oIE = CreateObject(“InternetExplorer.Application”)

 

Microsoft HTML Object Library

EARLY BINDING LATE BINDING
REFERENCE Microsoft HTML Object Library
(mshtml.tlb)
EXAMPLE Dim oHTMLDoc As MSHTML.HTMLDocument


Set oHTMLDoc = New MSHTML.HTMLDocument

Dim oHTMLDoc As Object


Set oHTMLDoc = CreateObject(“HTMLFile”)

 

Microsoft PowerPoint XX.X Object Library

EARLY BINDING LATE BINDING
REFERENCE Microsoft PowerPoint XX.X Object Library
(msppt.olb)
EXAMPLE Dim oPowerPoint As PowerPoint.Application


Set oPowerPoint = New PowerPoint.Application

Dim oPowerPoint As Object


Set oPowerPoint = CreateObject(“PowerPoint.Application”)

 

Microsoft Scripting Runtime

EARLY BINDING LATE BINDING
REFERENCE Microsoft Scripting Runtime
(scrrun.dll)
EXAMPLE
DICTIONARY
Dim oDictionary As Scripting.Dictionary


Set oDictionary = New Scripting.Dictionary

Dim oDictionary As Object


Set oDictionary = CreateObject(“Scripting.Dictionary”)

EXAMPLE
FSO
Dim oFSO As Scripting.FileSystemObject


Set oFSO = New Scripting.FileSystemObject

Dim oFSO As Object


Set oFSO = CreateObject(“Scripting.FileSystemObject”)

 

Microsoft Speech Object Library

EARLY BINDING LATE BINDING
REFERENCE Microsoft Speech Object Library
(sapi.dll)
EXAMPLE Dim oSpVoice As SpeechLib.SpVoice


Set oSpVoice = New SpeechLib.SpVoice

Dim oSpVoice As Object


Set oSpVoice = CreateObject(“SAPI.SpVoice”)

 

Microsoft Windows Image Acquisition Library vX.X

EARLY BINDING LATE BINDING
REFERENCE Microsoft Windows Image Acquisition Library vX.X
(wiaaut.dll)
EXAMPLE
IMAGEFILE
Dim oImageFile                As WIA.ImageFile


Set oImageFile = New WIA.ImageFile

Dim oImageFile               As Object


Set oImageFile = CreateObject(“WIA.ImageFile”)

EXAMPLE
IMAGEPROCESS
Dim oImageProcess As WIA.ImageProcess.


Set oImageProcess = New WIA.ImageProcess

Dim oImageProcess As Object


Set oImageProcess = CreateObject(“WIA.ImageProcess “)

 

Microsoft Windows Installer Object Library

EARLY BINDING LATE BINDING
REFERENCE Microsoft Windows Installer Object Library
(msi.dll)
EXAMPLE Dim oMSI As WindowsInstaller.installer


Set oMSI = CreateObject(“WindowsInstaller.Installer”)

Dim oMSI As Object


Set oMSI = CreateObject(“WindowsInstaller.Installer”)

 

Microsoft Word XX.X Object Library

EARLY BINDING LATE BINDING
REFERENCE Microsoft Word XX.X Object Library
(msword.olb)
EXAMPLE Dim oWord As Word.Application


Set oWord = New Word.Application

Dim oWord As Object


Set oWord = CreateObject(“Word.Application”)

 

Microsoft XML

EARLY BINDING LATE BINDING
REFERENCE Microsoft XML, vX.X
(msxml6.dll)
EXAMPLE Dim oHttp As MSXML2.XMLHTTP60


Set oHttp = New MSXML2.XMLHTTP60

Dim oHttp As Object


Set oHttp = CreateObject(“MSXML2.XMLHTTP.6.0”)

 

Microsoft VBScript Regular Expressions

EARLY BINDING LATE BINDING
REFERENCE Microsoft VBScript Regular Expressions X.X
(vbscript.dll)
EXAMPLE Dim oregEx As VBScript_RegExp_55.RegExp


Set oregEx = New VBScript_RegExp_55.RegExp

Dim oregEx As Object


Set oregEx = CreateObject(“VBScript.RegExp”)

 

Microsoft WMI Scripting VX.X Library

EARLY BINDING LATE BINDING
REFERENCE Microsoft WMI Scripting VX.X Library
(wbemdisp.tlb)
EXAMPLE Dim oWMI As WbemScripting.SWbemServices


Set oWMI = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2”)

Dim oWMI As Object


Set oWMI = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2”)

Note: There are different namespace that can be used ‘\root\cimv2’.
 

Microsoft Script Control 1.0

EARLY BINDING LATE BINDING
REFERENCE Microsoft Script Control 1.0
(msscript.ocx)
EXAMPLE Dim oScriptControl As MSScriptControl.ScriptControl


Set oScriptControl = New MSScriptControl.ScriptControl

Dim oScriptControl As Object


Set oScriptControl = CreateObject(“MSScriptControl.ScriptControl”)

Note: Does not work in 64-bit! Refer to: https://github.com/tablacus/TablacusScriptControl
 

Windows Script Host Object Model

EARLY BINDING LATE BINDING
REFERENCE Windows Script Host Object Model
(wshom.ocx)
EXAMPLE
WSCRIPT.SHELL
Dim oWshShell As IWshRuntimeLibrary.WshShell


Set oWshShell = New IWshRuntimeLibrary.WshShell

Dim oWshShell As Object


Set oWshShell = CreateObject(“WScript.Shell”)

EXAMPLE
WSCRIPT.NETWORK
Dim oWshNetwork As IWshRuntimeLibrary.WshNetwork


Set oWshNetwork = New IWshRuntimeLibrary.WshNetwork

Dim oWshNetwork As Object


Set oWshNetwork = CreateObject(“WScript.Network”)

 

Microsoft Shell Controls And Automation

EARLY BINDING LATE BINDING
REFERENCE Microsoft Shell Controls And Automation
(shell32.dll)
EXAMPLE Dim oShell As Shell32.Shell


Set oShell = New Shell32.Shell

Dim oShell As Object


Set oShell = CreateObject(“Shell.Application”)

 



Access软件网官方交流QQ群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助