Hello,
I am trying to insert a macro in another workbook with vba. I found a a very good example for this and copied it. When I run code below I get an error message on first declaration "Dim VBProj as VBIDE.VBProject". It says "User defined type not defined".
Any ideas?
---------------------------------------------------------------------------
Sub CreateGraphMacro()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As CodeModule
Dim LineNum As Long
Const DQUOTE = """" ' one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("Module1")
Set CodeMod = VBComp.CodeModule
ActiveSheet.Buttons.Add(5, 5, 50, 15).Select
Selection.OnAction = Test
Selection.Characters.text = "Button"
With CodeMod
LineNum = .CountOfLines + 1
.InsertLines LineNum, "Public Sub Test()"
LineNum = LineNum + 1
.InsertLines LineNum, ".........."
LineNum = LineNum + 1
.InsertLines LineNum, "End Sub"
End With
End Sub
------------------------------------------------------------------------------
Thanks,
Stefan
Bookmarks