我使用 Excel 处理 VBA,在 windows OS(32 位)和 office 2007(office 32 位)上工作正常当我开始在 Windows 8(64 位)和 office 2010(64 位)上工作时,我无法运行应用程序所以对于我添加的以下代码行,因为 excel office 2010 带有 VBA7。
#If VBA7 Then
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
#If VBA7 Then
Declare PtrSafe Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As LongPtr, ByVal dwShareMode As LongPtr, ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As LongPtr, ByVal dwFlagsAndAttributes As LongPtr, ByVal hTemplateFile As LongPtr) As Long
Declare PtrSafe Function WriteFile Lib "kernel32.dll" (ByVal hFile As LongPtr, ByRef lpBuffer As Any, ByVal nNumberOfBytesToWrite As LongPtr, ByRef lpNumberOfBytesWritten As LongPtr, ByRef lpOverlapped As LongPtr) As Long
Declare PtrSafe Function ReadFile Lib "kernel32" (ByVal hFile As LongPtr, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As LongPtr, ByRef lpNumberOfBytesRead As LongPtr, ByRef lpOverlapped As Any) As Long
Declare PtrSafe Function CloseHandle Lib "kernel32.dll" (ByVal hObject As LongPtr) As Long
#Else
Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Declare Function WriteFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, ByRef lpNumberOfBytesWritten As Long, ByRef lpOverlapped As Long) As Long
Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, ByRef lpOverlapped As Any) As Long
Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
#End If
它工作得很好但是当我尝试访问应用程序(excel表)时,我得到了
错误“运行时错误 429 - ActiveX 组件无法创建对象”
我的问题:我只遇到 64 位 Windows 8 和 64 位 Office 2010的问题
上面声明的代码有什么错误吗?
可以强制在 64 位操作系统上运行 32 位 COM 对象吗?
在这里创建对象
Dim objScript As New ScriptControl
Dim objNavFunctions As New NavFunctions
....
....
....
objScript.Language = "vbscript" ' **// here getting error