macro problem

T

TommyBoy

i have a macro i created that emails worksheets, it needs to be used on
different workbooks, but when i import it into a workbook at runtime it
doesn't find it, do i have to save the vbproject first? or does anyone
know what is going on?
 
I

Inbar

How did you create the macro?
If you use the VBA editor you can save the macro as part of a worksheet or
in the xlb file so it will be there everytime you launch Excel.

Inbar.
 
T

TommyBoy

i created the macro in one worksheet and then exported it to use it in
other files, because other excel apps will need to use, so i'm trying to
do it at run time like this: (it says it can't find the macro)

//this will add a reference to outlook
excelWorkbook.VBProject.References.AddFromFile(@"C:\Program
Files\Microsoft Outlook\OFFICE11\msoutl.olb");

//this imports the macro to my file
excelWorkbook.VBProject.VBComponents.Import(@"C:\Temp\ActiveSheet.bas");

//this runs it
excelApp.GetType().InvokeMember("Run",System.Reflection.BindingFlags.Default
| System.Reflection.BindingFlags.InvokeMethod,null, excelApp,new
Object[]{"'" + emFile.Name.ToString().Trim() +
"'!SendActiveSheet.SendActiveSheet"});
 
T

TommyBoy

how do i save it to the xlb file?
How did you create the macro?
If you use the VBA editor you can save the macro as part of a worksheet or
in the xlb file so it will be there everytime you launch Excel.

Inbar.

:
 
T

Tom Ogilvy

You don't save macros to xlb files. Inbar is mistaken. xlb files hold
menu modifications.
 
I

Inbar

You open the xlb from excel, go to VBA, import the code, and save it back to
the xlb.
 
N

Norman Jones

Hi Inbar,

See Tom Ogilvy's adjacent response to TommyBoy!

The xlb file stores toolbar customisations - it does not (and cannot) store
macros. Opening the xlb file restores the toolbar configurations that
applied when Excel was last closed, it does not present a VBA-readable file.
 
Top