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

ExcelVbaProject Constants Property

Dec 11, 2013 at 11:53 PM
Anyone had success using this property? When I set this property:

_package.Workbook.VbaProject.Constants = "SbA = 1"
and then save the workbook I cannot open the workbook in Excel. It complains about it being corrupted.

When I read in a workbook that has conditional compilation arguments set I can successfully read them using _package.Workbook.VbaProject.Constants.

If I then set _package.Workbook.VbaProject.Constants =_package.Workbook.VbaProject.Constants and save the workbook it is corrupted again. Seems like a bug in the code?

I then looked where this is being added to the file:
bw.Write((ushort)0x0C); //ID
        bw.Write((uint)Constants.Length);              //Size
        bw.Write(Encoding.GetEncoding(CodePage).GetBytes(Constants));              //Help context id
        bw.Write((ushort)0x3C);                                           //ID
        bw.Write((uint)Constants.Length/2);                              //Size
        bw.Write(Encoding.Unicode.GetBytes(Constants));  //HelpFile2
But honestly this is the part of eeplus I don't really understand. The comments regarding Help context and helpfile2 seem suspicious.

Dec 12, 2013 at 8:57 PM
I solved the problem by commenting out the following lines:
//bw.Write((ushort)0x3C); //ID
        //bw.Write((uint)Constants.Length/2);                              //Size
        //bw.Write(Encoding.Unicode.GetBytes(Constants));  //HelpFile2