La cosa sarebbe un po' OT ma, analizzando la funzione e utilizzando anche la funzione GetSystemDirectory, in pratica la cosa potrebbe essere gestita così per decidere se copiare i file nella cartella di sistema in base a Windows a 64bit o 32bit ed utilizzare
il relativo regsvr32.exe per la registrazione del componente.
'----
Option Explicit
Private Declare Function GetSystemDirectory Lib "kernel32" Alias _
"GetSystemDirectoryA" (ByVal lpBuffer As String, _
ByVal uSize As Integer) As Integer
Private Declare Function GetSystemWow64Directory Lib "Kernel32.dll" Alias _
"GetSystemWow64DirectoryA" (ByVal lpBuffer As String, _
ByVal uSize As Integer) As Integer
Sub Fix_MSCAL_OCX()
Dim Risp As Integer
Risp = MsgBox("Verrà lanciata la procedura per il Fix della mancata presenza del componente aggiuntivo MSCAL.OCX." & vbCrLf & _
"Assicurarsi che i file MSCAL.OCX e MSCAL.HLP, forniti assieme a questo file, siano salvati nella stessa directory" & _
"in cui è salvato questo file." & vbCrLf & "Continuare?", vbQuestion + vbOKCancel + vbDefaultButton1, "Fix MSCAL.OCX")
If Risp = vbCancel Then Exit Sub
Const sMsCalOcxName = "MSCAL.OCX"
Const sMsCalHelpName = "MSCAL.HLP"
Const sExeName = "regsvr32.exe"
Dim FSO As Object
Dim sOriginPathFile As String
Dim sDestinationPath As String
Dim FindDestinationPath As String * 255
Dim GSW64D As Integer, GSD As Integer
GSW64D = GetSystemWow64Directory(FindDestinationPath, Len(FindDestinationPath))
If GSW64D <> 0 Then
sDestinationPath = Left(FindDestinationPath, GSW64D)
Else
GSD = GetSystemDirectory(FindDestinationPath, Len(FindDestinationPath))
sDestinationPath = Left(FindDestinationPath, GSD)
End If
sDestinationPath = sDestinationPath & Application.PathSeparator
Set FSO = CreateObject("Scripting.FileSystemObject")
sOriginPathFile = ThisWorkbook.Path & Application.PathSeparator
With FSO
If .FolderExists(sDestinationPath) Then
If .FileExists(sOriginPathFile & sMsCalOcxName) And .FileExists(sOriginPathFile & sMsCalHelpName) Then
.CopyFile sOriginPathFile & sMsCalOcxName, sDestinationPath, True
.CopyFile sOriginPathFile & sMsCalHelpName, sDestinationPath, True
.DeleteFile sOriginPathFile & sMsCalOcxName
.DeleteFile sOriginPathFile & sMsCalHelpName
MsgBox "I files " & sMsCalOcxName & " e " & sMsCalHelpName & " sono stati copiati in " & sDestinationPath, vbInformation, "Fix MSCAL.OCX"
Call Shell("cmd.exe /C" & sDestinationPath & sExeName & " " & sMsCalOcxName, vbHide)
Else
MsgBox "I files " & sMsCalOcxName & " e " & sMsCalHelpName & " non sono presenti in " & sOriginPathFile & vbCrLf & _
"Copiare i files in " & sOriginPathFile & " e lanciare nuovamente il Fix!", vbCritical, "Fix MSCAL.OCX"
Exit Sub
End If
Else
MsgBox "La directory " & sDestinationPath & " non esiste!" & vbCrLf & _
"La procedura verrà interrotta.", vbCritical, "Fix MSCAL.OCX"
Exit Sub
End If
End With
Set FSO = Nothing
End Sub
'---
Per farla "completa" dovrei cercare che le dichiarazioni API in caso di utilizzo con Office a 64bit siano compatibili così come sono o se debbano essere dichiarate tramite
PtrSafe (andando a impostare le dichirazioni tramite la condizione #If VBA7 ... #then ... #Else.