Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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


  #2   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Import and run Macro

hi,
did you check the vb editor to see what it did import if
anything?
i played with it but couldn't get it to work either.
Dim VBCodeMod As CodeModule. codemodule does not exist at
this point
ActiveWorkbook.VBProject.VBComponents
("NewModule").CodeModule
i never got past this. Scrip out of range error.

why are you doing things this way. why not just copy the
other procedure and paste it in the project?

-----Original Message-----
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:\CDO_Email_New.bas"")" &
Chr(13) & _
"End Sub"
End With

Application.Run "CDOEmail"

End Sub


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Import and run Macro

Yeah, the code does get entered into the new module ok. So when I look at
the new module, I see
Sub CDOEmail()
ThisWorkbook.VBProject.VBComponents.Import(""H:\CD O_Email_New.bas"")_
End Sub
So it creates the code correctly. But I just can't get the code to execute
the newly created CDOEmail code.


wrote in message
...
hi,
did you check the vb editor to see what it did import if
anything?
i played with it but couldn't get it to work either.
Dim VBCodeMod As CodeModule. codemodule does not exist at
this point
ActiveWorkbook.VBProject.VBComponents
("NewModule").CodeModule
i never got past this. Scrip out of range error.

why are you doing things this way. why not just copy the
other procedure and paste it in the project?

-----Original Message-----
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:\CDO_Email_New.bas"")" &
Chr(13) & _
"End Sub"
End With

Application.Run "CDOEmail"

End Sub


.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Import and run Macro

Steph,

Try changing

Application.Run "CDOEmail"

to

Application.Run VBCodeMod.Name & ".CDOEmail"

--

HTH

RP

"Steph" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import macro Gene Augustin Excel Discussion (Misc queries) 2 March 2nd 09 10:28 PM
Import data and macro Jambruins Excel Discussion (Misc queries) 5 October 24th 07 02:37 PM
Import CSV files using Macro Mintz87 New Users to Excel 3 August 29th 05 09:48 PM
import data using macro chris_rip Excel Discussion (Misc queries) 0 July 18th 05 08:32 PM
Macro import Lynn[_2_] Excel Programming 3 August 7th 03 10:18 PM


All times are GMT +1. The time now is 11:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"