Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > Major issue with Excel 2003 & 2007 when trying to do a reference in one cell from other cell in another Tab while doing a call to Excel in another thread
Ask a questionAsk a question
 

General DiscussionMajor issue with Excel 2003 & 2007 when trying to do a reference in one cell from other cell in another Tab while doing a call to Excel in another thread

  • Tuesday, November 03, 2009 9:55 AMjjs2009 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    You can’t do the reference : other cell in the first tab is update with #REF

    Way to reproduce it:

    I use the Andrew Whitechapel’s project : Implementing IMessageFilter in an Office add-in

     

    http://blogs.msdn.com/andreww/archive/2008/11/19/implementing-imessagefilter-in-an-office-add-in.aspx

     

    I change the following lines of codes:

     

            private void CallExcel()

            {

                try

                {

                    this.Application.ActiveCell.Value2 = DateTime.Now.ToShortTimeString();

                }

    …..

     

    By

     

            private void CallExcel()

            {

                try

                {

                    this.Application.StatusBar= DateTime.Now.ToShortTimeString();

                }

    ….

     

     

    And:

            private void RegisterFilter()

            {

                // Message filters are per-thread, so we register this thread

                // as a message filter (not the main thread that the add-in is

                // created on - because that's Excel's main thread).

                CoRegisterMessageFilter(this, out oldMessageFilter);

     

                // Sleep for long enough so the user can pop up a dialog in Excel,

                // to make sure Excel is blocked.

                    Thread.Sleep(3000);

                    CallExcel();

            }

     

     

    By

     

            private void RegisterFilter()

            {

                // Message filters are per-thread, so we register this thread

                // as a message filter (not the main thread that the add-in is

                // created on - because that's Excel's main thread).

                CoRegisterMessageFilter(this, out oldMessageFilter);

     

                // Sleep for long enough so the user can pop up a dialog in Excel,

                // to make sure Excel is blocked.

                while (true)

                {

                    Thread.Sleep(200);

                    CallExcel();

                }

            }

     

    When you click on AsyncCall menu in the Rubbon, it start trying to put the hour in the status bar.

    If you try to reference a cell in another tab, you will receive nothing & another cell will be updated with #REF value or 0

     

     

     

     

     

     

     

All Replies

  • Tuesday, November 03, 2009 10:35 AMCindy MeisterMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Office applications are single threaded, so if you're trying to work with multiple threads you're going to run into difficulties.
    Cindy Meister, VSTO/Word MVP
  • Wednesday, November 18, 2009 2:47 AMBessie ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    We are changing the issue type to "General Discussion" because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to "Question" by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.