Public Sub RegisterComponent(sFilename As String, Optional bUnRegister As Boolean = False, Optional bHideResults As Boolean = True)
If Len(Dir$(sFilename)) = 0 Then
'File is missing
MsgBox "Unable to locate file "" & sFileName & """, vbCritical
Else
If bUnRegister Then
'Unregister a component
If bHideResults Then
'Hide results
Shell "regsvr32 /s /u " & """" & sFilename & """"
Else
'Show results
Shell "regsvr32 /u " & """" & sFilename & """"
End If
Else
'Register a component
If bHideResults Then
'Hide results
Shell "regsvr32 /s " & """" & sFilename & """"
Else
'Show results
Shell "regsvr32 " & """" & sFilename & """"
End If
End If
End If
End Sub
For example :
Sub test()
RegisterComponent ("c:\test.dll")
End Sub
Here is a function to export a section of registry to .reg file
Public Sub RegeditExport(sKey As String, sFilename As String)
Shell "regedit.exe /s /e " & Chr(34) & sFilename & Chr(34) & " " & Chr(34) & sKey & Chr(34), vbHide
End Sub
Here is a function to import windows registry file (.reg file) to the registry
Public Sub RegeditImport(sFilename As String)
Shell "regedit.exe /s /c " & Chr(34) & sFilename & Chr(34), vbHide
End Sub
For example:
Sub test()
RegeditImport "C:\test.reg"
End Sub
Regarding the RegeditImport function, it gets an error message, viz.
ReplyDelete"Runtime error 5. Invalid call procedure or argument."
Please help. I really would like to import a registry file by using vba.
Thank you.