View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default Execution of an externally created VBA code

You can import VBA modules into an Excel project at runtime. Then execute.
You can't import and run the module from within the same procedure, so you
have to call another procedure to get it to run.

Example: If the file Module1.bas has a procedure called runme, then you
could do the following:

Sub test()
ThisWorkbook.VBProject.VBComponents.Import "C:\T\Module1.bas"
test2
End Sub

Sub test2()
runme
End Sub

I have examples of VBA at runtime on my website.

Chip Pearson has some decent information on the topic too:
http://www.cpearson.com/excel/vbe.htm


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Reinhard F. Bentrup" wrote in message
...
Hi,

how can I execute a VBA code in EXCEL which has been created by an

external
application (C Applikations such as LabWindows CVI) as ASCII code file?

My C application acquires a couple of thousand numbers which I like to

open
in EXCEL. The C application writes an CSV-File and launches EXCEL. Now

EXCEL
needs to execute a VBA code to format data, created charts etc. which also
has been created by the application as ASCII file (can't be a fixed makro
since the formatting depends on the settings and results of my

application).
Once the VBA code is in EXCEL I can launch it via DDE or similar.

Alternatively, can I execute VBA code transfered to EXCEL via DDE?

Thanks - Reinhard