PDA

View Full Version : Run time error '429': ActiveX component can't create object



Devendra
04-20-2013, 06:21 AM
I working on VBA with Excel, Which working fine with windows OS (32 bit) and office 2007(office 32 bit) When i started work on Windows 8 (64 bit) and office 2010 (64 bit) i was unable to run the application so for below line of code i added because of excel office 2010 is comes with 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

it worked fine But when i try to Access the Application(excel sheet) i am getting

Error "Runtime Error 429 - ActiveX Component Can't Create Object "


My Problem : I Have Issue only with 64 bit Windows 8 and 64 bit Office 2010
1. did any mistake in above Declared Code ?
2. Can force to run 32 bit COM object on 64 bit OS and How ?

Here creating the COM Object

Dim objScript As New ScriptControl

Dim objNavFunctions As New NavFunctions
....
....
....
objScript.Language = "vbscript" ' **// here getting error

Kenneth Hobs
04-20-2013, 06:51 PM
Rather than referencing c:\windows\system32\msscript.oxc, Microsoft Script Control 1.0, instead reference: c:\windows\syswow64\MScript.ocx.

Devendra
04-21-2013, 12:01 AM
I am new in VBA Programming,Could you please share line of code to reference: c:\windows\syswow64\MScript.ocx and where i should add the code.

sassora
04-21-2013, 01:23 AM
Tools / References

Devendra
04-21-2013, 02:43 AM
Sassora, what do you mean ? Please share the Reference to run c:\windows\syswow64\MScript.ocx on 64 bit (office and OS).

sassora
04-21-2013, 07:39 AM
To browse references, Go to the tools menu and select the first entry. Take a look at this : http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/2c9cee39-2c05-4006-8a2b-f5f0351f980b

Kenneth Hobs
04-21-2013, 08:48 AM
In the Visual Basic Editor (VBE), select the menus Tools > References. Select the Browse button and browse to the file to add to the reference list if it is not listed. IF you need a picture of how to do references see: http://www.your-save-time-and-improve-quality-technologies-online-resource.com/set-references-excel-vba.html

While that object can be of use on a few occasions, using VBA itself will usually be more than adequate to solve a problem. Referencing FileScripting Object (FSO) will help with some projects as well. For example, VBA has file read/write solutions and other object methods like FSO do too.

When dealing with API funtions, yes you do need to code as you did to account for the differences in 32 bit versus 64 bit functions.

Aflatoon
04-22-2013, 02:09 AM
FYI, your 64bit declarations should be:
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare PtrSafe Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As LongPtr) As LongPtr
Declare PtrSafe Function WriteFileEx Lib "kernel32" Alias "WriteFileEx" (ByVal hFile As LongPtr, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpOverlapped As OVERLAPPED, ByVal lpCompletionRoutine As LongPtr) As Long
Declare PtrSafe Function ReadFile Lib "kernel32" Alias "ReadFile" (ByVal hFile As LongPtr, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As OVERLAPPED) As Long

Devendra
04-22-2013, 10:37 AM
Hi Kenneth, Here is the Code By using ScriptControl (ActiveX control) i want to perform following things.
Dim objScript As New ScriptControl
objScript.Language = "vbscript"
objScript.Timeout = 10000000
Call objScript.AddObject("masterworkbook", ThisWorkbook,True)
How can achieve that by using VBA in build Function or any replacement of ScriptControl ?.

Kenneth Hobs
04-22-2013, 11:09 AM
What is the purpose or goal? What is timeout for?

In Excel's VBA, ThisWorkbook is set by default. You can always set it to some other workbook object name if needed. e.g

Option Explicit

Sub ken()
Dim twb As Workbook
Set twb = ThisWorkbook
MsgBox twb.Name
End Sub

For Timeout, maybe look at:
Application.OnTime

Devendra
04-22-2013, 11:50 AM
Goal is :
1. When Clicked on Hyperlink ,IE window (DialogBox) should open with displaying downloading the xml file.
2. After Downloaded the xml file , Browser should open with URL.

Timeout property offers a safety shield to prevent a script program from going into an infinite loop and locking up the system. You can specify the maximum amount of time that a script can run before a warning message is displayed.

AddObject is Makes an object available for the script programs. Which Contains workbook fullpath and file name.

Kenneth Hobs
04-22-2013, 12:09 PM
I am not sure how this relates to your post. I noticed that you asked the question in another forum as well. As in the other forum response, please just post what is pertinent to one problem.

By clicking hyperlink, what is meant, in Excel, MSIE, etc.? If in Excel, please post the link or an Excel file with the link which is preferable. If file is attached, include code.

Try to isolate your problem and just give us that. This is how I solve problems.

If just downloading an XML file is all that is needed, there are other ways to do it of which some include timeout options.