This project has moved and is read-only. For the latest updates, please go here.

Saving Excel VBA Code

Oct 31, 2011 at 10:39 AM

Hi All

I'm trying to create Excel File with VBA Code but I'm not able to save the code in the file !

Even if I use the Example07 I could save the file but when I open it I couldn't find the code.

I'm sure there is something wrong with my Office configuration but I tried almost every parameter change without success.

Any suggestions ?

Thank you in advance

Oct 31, 2011 at 4:10 PM

hey dbarile,

which office version do you have?
you dont have an exception but the vba code is missing?
this is magical.. i try to reproduce the effect with some option changes in office.
i nee to know: windows version 32/64Bit Office version 32/64Bit and at  last, do you have
any security solutions installed?



Nov 1, 2011 at 12:02 PM

Hi Sebastian

I'm using Office Ultimate 2007 SP3 on a Windows 7 Ultimate N 64bit with SP1. I'm using Microsoft Security Essentials as security solution.

I haven't any exception and If I leave excel as visible I could see that the code is really created in the excel file. After saving and reopening the code is missing !

I'll try to use NetOffice on my own PC this evening to let you know the differences (on my notebook I have Windows Vista Ultimate SP2 32 bit and Microsoft Office 2007).

Thank you


Nov 1, 2011 at 3:52 PM

Hi Sebastian. I have the same issue on my notebook. I tried .Net 4.0 and .Net 3.5 solution. I'm using VS2010 as in my office. Should I give you other information ?

Thanks a lot !


Nov 1, 2011 at 6:34 PM

i do some detailed tests with 2007 und windows7. some security suites kill created vba code btw.
you save the file to .xlsx ?

Nov 2, 2011 at 8:45 AM

Yes, I save files as .xlsx. I tried few minutes ago to save .xls as NetOffice.ExcelApi.Enums.XlFileFormat.xlExcel8 and the code is correctly saved.



Nov 2, 2011 at 11:18 AM

okay now i see. in excel 2007 and 2010 you have to give this parameter, but only in this versions, the enum member is only supported here.

// SupportByLibrary Excel 12, 14
xlExcel8 = 56

if you want to support older version you have to check the version dynamicly and write an else statement with a save method without this parameter.
is that okay for you?


Nov 2, 2011 at 11:39 AM

Sure it's ok for me. Thank you for help!

Last question: is there an example with code to create a macro and assing it to a keyboard shortcut ?


Nov 4, 2011 at 3:29 PM

Sebastian, I need to ask you to investigate more on this problem. I need to create files with more then 256 columns and using this workaround I couldn't do it !

Thank you


Nov 4, 2011 at 4:15 PM

hey domenico,

you mean using the xlExcel8 flag kills you columns?
gimme this weekend to clarify the situation and read a little bit about the XlFileFormat enum and the specific members.

kind regards*

Nov 4, 2011 at 4:34 PM

Ciao Sebastian, when I open the file saved with xlExcel8 flag I have only 256 columns.

Excel 2003 files has limit of 256 columns and 65000 rows

Have a nice weekend ;-)

Kindly regards,


Nov 4, 2011 at 4:41 PM

hey domenico,
yeah thats the reason for i want to see for a format flag to save the document in modern format -with vba projects-.
hope i find them but its possible, i'm sure.
see you* ;-)

Nov 9, 2011 at 3:22 PM

i do a test and the xlWorkbookNormal flag works fine for me.
*regards and something other