View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Steph[_3_] Steph[_3_] is offline
external usenet poster
 
Posts: 312
Default Import and run Macro

Hi. The below code inserts VBA code via VBA code. The code it inserts is
code to Import a much larger procedure. So i was hoping to write the code
via code, and then execute the newly written code that imports the macro.
But when I call the new procedure, I get a "macro does not exist error".
Anyone see what is wrong with this code? Thanks!

Sub AddProcedure()

Dim VBCodeMod As CodeModule
Dim LineNum As Long

Set VBCodeMod =
ActiveWorkbook.VBProject.VBComponents("NewModule") .CodeModule
With VBCodeMod
LineNum = .CountOfLines + 1
.InsertLines LineNum, _
"Sub CDOEmail()" & Chr(13) & _
"ThisWorkbook.VBProject.VBComponents.Import(""H:\C DO_Email_New.bas"")" &
Chr(13) & _
"End Sub"
End With

Application.Run "CDOEmail"

End Sub