Execution of an externally created VBA code

  • Thread starter Reinhard F. Bentrup
  • Start date
R

Reinhard F. Bentrup

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
 
R

Rob van Gelder

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
 
R

Reinhard F. Bentrup

Thanks for the references, after having read through some of them I'm
wondering whether it might be even easier to directly access to the EXCEL
objects out of my C application. Is this possible? Can you reference an
example?

Thanks - Reinhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top