Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default loading vba code in excel from within C#

Hello,

I generate a new excel file from with code (C#), in this new excel I write
data, ... As a final step I need to call some code (formatting written as a
macro and stored in a module.bas). I want to load this module dynamically
from within my newly created excel file, but I don't find how I can do this.
Can anybody help me with this?

Thanks,
Laura G.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default loading vba code in excel from within C#

Hi,

Just found in my data that Chip Pearson shows on his site how to do this.
Regards
JY
"Laura G." wrote in message
...
Hello,

I generate a new excel file from with code (C#), in this new excel I write
data, ... As a final step I need to call some code (formatting written as
a
macro and stored in a module.bas). I want to load this module dynamically
from within my newly created excel file, but I don't find how I can do
this.
Can anybody help me with this?

Thanks,
Laura G.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default loading vba code in excel from within C#

Try

xlApplication.Run "MacroName"

where
xlApplication is your Excel.Application variable
"MacroName" is the name of the subroutine you want to execute.

"Laura G." wrote:

Hello,

I generate a new excel file from with code (C#), in this new excel I write
data, ... As a final step I need to call some code (formatting written as a
macro and stored in a module.bas). I want to load this module dynamically
from within my newly created excel file, but I don't find how I can do this.
Can anybody help me with this?

Thanks,
Laura G.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default loading vba code in excel from within C#

The sytax I gave is for VB. There should be an equivalent for C#. The main
point is to use the Run method of the Excel Application object.


"Vergel Adriano" wrote:

Try

xlApplication.Run "MacroName"

where
xlApplication is your Excel.Application variable
"MacroName" is the name of the subroutine you want to execute.

"Laura G." wrote:

Hello,

I generate a new excel file from with code (C#), in this new excel I write
data, ... As a final step I need to call some code (formatting written as a
macro and stored in a module.bas). I want to load this module dynamically
from within my newly created excel file, but I don't find how I can do this.
Can anybody help me with this?

Thanks,
Laura G.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default loading vba code in excel from within C#

I found my answer indeed; for others looking at this:

app = new Excel.Application();
app.Workbooks.Open(filename,Type.Missing, false, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

Excel.Workbook wb = app.Workbooks[1];

//open a saved module ex: c:\module1.bas
wb.VBProject.VBComponents.Import(vbFileName);

app.Run(macroName, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);

wb.Save();
app.Quit();

"Jean-Yves" wrote:

Hi,

Just found in my data that Chip Pearson shows on his site how to do this.
Regards
JY
"Laura G." wrote in message
...
Hello,

I generate a new excel file from with code (C#), in this new excel I write
data, ... As a final step I need to call some code (formatting written as
a
macro and stored in a module.bas). I want to load this module dynamically
from within my newly created excel file, but I don't find how I can do
this.
Can anybody help me with this?

Thanks,
Laura G.




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
excel loading whyrrsd Excel Discussion (Misc queries) 0 May 13th 07 08:55 AM
Disable VBA code execution when loading a workbook Charles Excel Discussion (Misc queries) 4 October 14th 05 09:12 PM
Loading excel Mike R Excel Discussion (Misc queries) 13 March 1st 05 07:04 PM
Addins not loading when opening from code Jack Excel Programming 3 February 15th 05 06:31 PM
Excel Add-In loading xlpuzzled Excel Discussion (Misc queries) 6 February 4th 05 01:00 AM


All times are GMT +1. The time now is 05:34 PM.

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

About Us

"It's about Microsoft Excel"