Answered Accessing a method in another worksheet class?

  • 29 กรกฎาคม 2555 19:15
     
     
    In C#, I have a method in one worksheet and I'm trying to call the method from another worksheet's code. What is the easiest way to do this? I set the method to public but I can't figure out how to access it...

ตอบทั้งหมด

  • 30 กรกฎาคม 2555 7:29
    ผู้ดูแล
     
     คำตอบ มีโค้ด

    Hi,

    Thanks for posting in the MSDN Forum.

    As far as I know, you can use the Globals class. For instance, add a public void Sheet2Method() to the Sheet2, and you can call it in the Sheet1 class in accordance with the following code

    namespace ExcelWorkbook1
    {
       public partial class Sheet1
       {
           private void Sheet1_Startup(object sender, System.EventArgs e)
           {
               Globals.Sheet2.Sheet2Method();
           }
           private void Sheet1_Shutdown(object sender, System.EventArgs e)
           {  
           }
       }
    }

    Hope this can help you.

    Best Regards


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    • ทำเครื่องหมายเป็นคำตอบโดย Leo_GaoModerator 3 สิงหาคม 2555 1:19
    •