ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ActiveX need help (https://www.excelbanter.com/excel-programming/325815-activex-need-help.html)

Mary

ActiveX need help
 
Hi Everyone,
I have a problem with my ActiveX component, in my code, I download the
relevant WINSOCK file and then install and register it. I found that when
using the ActiveX component in my class module, it comes up with an error
saying that it cannot find the component. But if I close the worksheet and
then reopen it, the error doesn't appear, and everything seems to install
fine...not sure if that is a problem with my download and register of the
ActiveX component...
Code is below...
__________________________________________________ _____________________
' This sub program checks to see if a particular folder exist
' If C:\WINNIT exist then the operating system is Windows 2000
' If C:\Windows exist then the operating system is Windows XP
' Then it checks to see if the ActiveX file exist in specific directory
' If file exist it continues to modify registry setting
' If files doesn't exist, it will download from server
' Then modify registry setting

Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Private Sub Workbook_Open()
Dim fso
Dim oShell
Dim folder As String
Dim file As String
Dim sSourceURL As String
Dim sLocalFile As String
Dim lReturn As Long
Dim lRegSvrReturn As Long
Dim RegistryKey As String
Dim KeyExist As Long
RegistryKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\Comm on"
Set oShell = CreateObject("WScript.Shell")

' Test to see if OS is Windows 2000
folder = "C:\WINNT\"
file = "System32\MSWINSCK.OCX"
sSourceURL = "http://www.aliensoftware.co.uk/Files0908/MSWINSCK.OCX"

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(folder) Then
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.Fileexists(folder & file) Then

' File doesn't exist - will download from server

sLocalFile = folder & file
lReturn = URLDownloadToFile(0, sSourceURL, _
sLocalFile, 0, 0)

' Register the ActiveX File

If lReturn = 0 Then
lRegSvrReturn = Shell("REGSVR32.EXE /s
C:\WINNT\System32\MSWINSCK.OCX")
Application.Wait Now + TimeValue("00:00:05")

End If
End If

' Set appropriate keys and values in registry - to suppress Excel Prompts
Shell ("REGSVR32.EXE /s C:\WINNT\System32\MSWINSCK.OCX")
oShell.RegWrite
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\Comm on\Security\UFIControls",
1, "REG_DWORD"

Else

' Test if OS is Window XP

folder = "C:\Windows\"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.Fileexists(folder & file) Then

' File doesn't exist - will download from server

sLocalFile = folder & file
lReturn = URLDownloadToFile(0, sSourceURL, _
sLocalFile, 0, 0)

' Register the ActiveX File

If lReturn = 0 Then
' This would fail if user does not have a partition name C:\ or
if C:\ is not the master drive with OS
lRegSvrReturn = Shell("REGSVR32.EXE /s
C:\WINDOWS\System32\MSWINSCK.OCX")
Application.Wait Now + TimeValue("00:00:05")
End If
End If

' Set appropriate keys and values in registry - to suppress Excel Prompts
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.Fileexists(folder) Then

' For Office Xp

Shell ("REGSVR32.EXE /s C:\WINDOWS\System32\MSWINSCK.OCX")
oShell.RegWrite
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\Comm on\Security\UFIControls",
1, "REG_DWORD"

' For Office 2003
Shell ("REGSVR32.EXE /s C:\WINDOWS\System32\MSWINSCK.OCX")
oShell.RegWrite
"HKEY_CURRENT_USER\Software\Microsoft\VBA\Security \LoadControlsInForms", 1,
"REG_DWORD"

Else

' For Office 2000
Shell ("REGSVR32.EXE /s C:\WINNT\System32\MSWINSCK.OCX")
oShell.RegWrite
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\Comm on\Security\UFIControls",
1, "REG_DWORD"

End If

End If
MsgBox ("Working so far...")
Test
End Sub
__________________________________________________ _____________________


All times are GMT +1. The time now is 12:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com