ActiveX need help

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Mary (Mary_at_discussions.microsoft.com)
Date: 03/21/05


Date: Sun, 20 Mar 2005 19:51:03 -0800

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\Common"
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\Common\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\Common\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\Common\Security\UFIControls",
1, "REG_DWORD"
    
    End If

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



Relevant Pages

  • RE: Output to PDF using Adobe Acrobat Professional?
    ... Will this option send all of my print jobs even outside of Access to Adobe? ... > You will want to chase down the registry tree to find the ... >> Dim strReportName As String ...
    (microsoft.public.access.reports)
  • Re: Reading Registry Values
    ... What is it I need to do in order to READ from this registry location? ... So, I built a quick little WinForm app that mimics the code of the Windows Service, but in this case it spits out to the screen process messages at various points so I can see where it is going fine and where it "breaks". ... Private Function GetRegKey(ByVal Item As String, Optional ByVal NoValRet As String = "") As String ... Dim Result As String = "" ...
    (microsoft.public.dotnet.languages.vb)
  • Remote registry read
    ... newsgroup on bulk registry read of remote machines but I can't seem to ... Dim aComputers(), aRegistryPaths ... 'User-defined function to read computer names into array ... Function GetRegistryValues(sMachine, sBranch, sSubKey, sNames) ...
    (microsoft.public.scripting.vbscript)
  • Re: Is there anyway to retrieve Registry Values from VBA???
    ... I also have an ActiveX DLL that wraps up all the registry functions in a nice VBA-friendly package. ... Dim MyName As String ... MyName = MyFullName() ... Function MyFullNameAs String ...
    (microsoft.public.excel.programming)
  • Re: Reading Registry Values
    ... Code I am using to read the registry value: ... Private Function GetRegKey(ByVal Item As String, ... Dim Result As String = "" ... The above "WriteEvent" is just for my test app so I can see what it ...
    (microsoft.public.dotnet.languages.vb)