J
Jim Andersen
Hi,
This should work... but it doesn't.
Who can spot the error ?
I open a document, add a macro, and try to run that macro, but I get error
80020003 (macro can not be found)
Sub ThisFails()
Dim Doc As Document
Dim MyRange As Range
Set Doc = Documents.Open(FileName:="c:\temp\tst2.RTF",
ConfirmConversions:=False, ReadOnly:= _
True, Format:=wdOpenFormatRTF, Visible:=False)
Dim VBComp As VBComponent
Dim VBCodeMod As CodeModule
Dim Code As String
Set VBComp = Doc.VBProject.VBComponents.Add(vbext_ct_StdModule)
VBComp.Name = "tstModule"
Set VBCodeMod = VBComp.CodeModule
Code = _
"Sub Hello()" & Chr(13) & _
" msgbox ""Hello World""" & Chr(13) & _
"End Sub"
VBCodeMod.InsertLines 1, Code
Application.Run "Hello"
End Sub
The macro is in there, and it works ok. But it won't run it.
tia
/jim
This should work... but it doesn't.
Who can spot the error ?
I open a document, add a macro, and try to run that macro, but I get error
80020003 (macro can not be found)
Sub ThisFails()
Dim Doc As Document
Dim MyRange As Range
Set Doc = Documents.Open(FileName:="c:\temp\tst2.RTF",
ConfirmConversions:=False, ReadOnly:= _
True, Format:=wdOpenFormatRTF, Visible:=False)
Dim VBComp As VBComponent
Dim VBCodeMod As CodeModule
Dim Code As String
Set VBComp = Doc.VBProject.VBComponents.Add(vbext_ct_StdModule)
VBComp.Name = "tstModule"
Set VBCodeMod = VBComp.CodeModule
Code = _
"Sub Hello()" & Chr(13) & _
" msgbox ""Hello World""" & Chr(13) & _
"End Sub"
VBCodeMod.InsertLines 1, Code
Application.Run "Hello"
End Sub
The macro is in there, and it works ok. But it won't run it.
tia
/jim