LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 190
Default 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
__________________________________________________ _____________________
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ActiveX RedChequer Excel Discussion (Misc queries) 0 March 9th 05 11:05 PM
ActiveX add-in? [email protected] Excel Programming 7 January 21st 05 01:04 PM
activeX batty Excel Programming 0 September 18th 04 04:13 PM
activex joe Excel Programming 1 August 12th 04 05:22 PM
activeX Marcos Santos \(MOS\) Excel Programming 0 July 21st 04 09:42 PM


All times are GMT +1. The time now is 07:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"