none
Best practices for locating Global items in VSTO Excel Workbook projects RRS feed

  • Question

  • VS 2010 Pro, Office 2007

    In most projects there is a need for globally accessible Constants, Methods, DataStructures, etc. In a fairly complex VSTO Workbook project, it is not obvious to me where to place such things. Some choices occur to me:

    1. in ThisWorkBook
    2. in a separate file within a Class declared as "Partial Friend NotInheritable Class Globals"
    3. in a separate file within a Module (in VB.Net)

    I am pretty sure that any of the above will work (maybe not #2).

    My question is what is the recommended/best practice/most generally used approach? My intent is that if someone (maybe me) tries to examine the project in a year or two, where is the first place that that someone will look for these global scope items.

    Thursday, August 25, 2011 9:42 PM

Answers

  • <<My intent is that if someone (maybe me) tries to examine the project in a year or two, where is the first place that that someone will look for these global scope items.>>

    ThisWorkbook, most likely...

    But there's nothing to stop you from maintaining these elsewhere if logic says they would be better managed that way. Just put a detailed comment at the very top of ThisWorkbook that outlines the code structures in the solution.

    As for #2, I was doing something similar to what you have in mind in an Add-in project the other day: the class members will probably need to be "SHARED", unless you're working with distinct class objects (Dim myClassObject as ClassThingy = New ClassThingy()). In the context I understand what you want to do, though, that's usually not the case. "Shared" members of a class can be accessed without needing an instance of the class.

    What I was doing: this was an IDTExtensibility2 Add-in (IOW not VSTO) to provide common Ribbon/Backstage functionality across multiple Office apps, based on data stored in a Custom XML Part. Lots of "Helper code" involved. I kept the code relevant to the Ribbon controls in the equivalent of "ThisAddin" and put the rest in a "Helper" class, all declared as Shared items.


    Cindy Meister, VSTO/Word MVP
    Friday, August 26, 2011 6:53 AM
    Moderator