Hi,

I have a situation where I am trying to access a MS Excel macro from a Visual Basic 6.0 application. The function of the macro is to 'protect' (make it read only) the excel file (that is not the way to protect an excel file but due to some specific conditions, we are having to do this via a macro). From the code, it works alright but when I make an exe and run the exe, it gives the following error:

Automation Error
Error accessing the OLE registry.
-2147319780 (8002801C)

The following is the code for creating and running the macro in VB:

Dim xlmodule As Object
Set xlmodule = m_objExcel.Workbooks(strWkbName).VBProject.VBComponents.Add(1)
Dim strCode As String
strCode = _
"Sub MyMacro()" & vbCr & _
" Application.EnableEvents = False" & vbCr & _
" ActiveSheet.Protect Password:=xyz123 & vbCr & _
" Application.EnableEvents = True" & vbCr & _
"End Sub"
xlmodule.CodeModule.AddFromString strCode
m_objExcel.Run "MyMacro"
Set xlmodule = Nothing


where object m_objExcel is Excel.Application and
object strWkbName is name of the workbook

Please help!

Thanks in advance
ourspt