In VSTO, the CodeName property is an infrastructure property that you should not use from your code.
From MSDN:
This property supports Visual Studio Office Infrastructure Tools and is not intended to be used directly from your code.
Tell us what you are trying to accomplish, maybe there is an alternative way to do what you want.
In addition, I noted from your code that you are using Excel Addin. You can check if the CodeName property CodeName what you expect if you use Excel Document Customization instead of Excel Addin.
Update: So that you can clearly label the worksheet, you can use the GUID and set it as a custom property of the worksheet using Worksheet.CustomProperties .
source share