+ Reply to Thread
Results 1 to 3 of 3

C# vba development

  1. #1
    Foeyshell
    Guest

    C# vba development

    I created a button, to dynamically create a validation on cell

    the following is the code i wrote:

    ......

    Excel.Range thisRange =
    ((Excel.Worksheet)(this.thisWorkbook.Worksheets.get_Item("XXXXX"))).get_Range("A1", Type.Missing);

    thisRange.Validation.Add(Excel.XlDVType.xlValidateList,
    Excel.XlDVAlertStyle.xlValidAlertStop,
    Excel.XlFormatConditionOperator.xlBetween,"Yes, No", Type.Missing);

    ......

    I tested, and found that thisRange is not null and thisRange.Validation is
    not null either. However, when i wrong the code, and clicked the button, it
    tells me "Object Reference is Not set to an instance of an object".

    But the range object is not, while validation is not null either. Can anyone
    help me solve this problem?

    Many thanks

  2. #2
    NickHK
    Guest

    Re: C# vba development

    Foeyshell,
    You are automating Excel from C# ?
    If so, may be microsoft.public.dotnet.languages.csharp would be a better
    place.

    NickHK

    "Foeyshell" <[email protected]> wrote in message
    news:[email protected]...
    > I created a button, to dynamically create a validation on cell
    >
    > the following is the code i wrote:
    >
    > .....
    >
    > Excel.Range thisRange =
    >

    ((Excel.Worksheet)(this.thisWorkbook.Worksheets.get_Item("XXXXX"))).get_Rang
    e("A1", Type.Missing);
    >
    > thisRange.Validation.Add(Excel.XlDVType.xlValidateList,
    > Excel.XlDVAlertStyle.xlValidAlertStop,
    > Excel.XlFormatConditionOperator.xlBetween,"Yes, No", Type.Missing);
    >
    > .....
    >
    > I tested, and found that thisRange is not null and thisRange.Validation is
    > not null either. However, when i wrong the code, and clicked the button,

    it
    > tells me "Object Reference is Not set to an instance of an object".
    >
    > But the range object is not, while validation is not null either. Can

    anyone
    > help me solve this problem?
    >
    > Many thanks




  3. #3
    Stephen Bullen
    Guest

    Re: C# vba development

    Hi Foeyshell,

    > I created a button, to dynamically create a validation on cell
    >
    > the following is the code i wrote:
    >
    > ......
    >
    > Excel.Range thisRange =
    > ((Excel.Worksheet)(this.thisWorkbook.Worksheets.get_Item("XXXXX"))).get_Range("A1", Type.Missing);
    >
    > thisRange.Validation.Add(Excel.XlDVType.xlValidateList,
    > Excel.XlDVAlertStyle.xlValidAlertStop,
    > Excel.XlFormatConditionOperator.xlBetween,"Yes, No", Type.Missing);
    >
    > ......
    >
    > I tested, and found that thisRange is not null and thisRange.Validation is
    > not null either. However, when i wrong the code, and clicked the button, it
    > tells me "Object Reference is Not set to an instance of an object".
    >
    > But the range object is not, while validation is not null either. Can anyone
    > help me solve this problem?


    This looks like a VSTO project. If so, the appropriate newsgroup is
    Microsoft.public.vsnet.vstools.office.

    Regards

    Stephen Bullen
    Microsoft MVP - Excel
    www.oaltd.co.uk



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1