Excel does not redraw iteself

  • Thread starter Thread starter Mircea Pleteriu
  • Start date Start date
M

Mircea Pleteriu

Hi,

I'm developing a class which opens the MS Excel
and extend the context menu with a new item. When the item is clicked all it
does is to popup a message box.
While the message box is displayed, it seems that Excel is locked up and not
redrawing its surface until message box control returns to it, that is,
until the message box is acknowledged.

I mention that my class is not a macro. It just accesses the Excel from
within an .NET Windows Application.

Any idea why MS Excel framwork does not get repaint while the message box is
shown?

Thanks,
Mircea
 
Mircea Pleteriu said:
Hi,

I'm developing a class which opens the MS Excel
and extend the context menu with a new item. When the item is clicked all it
does is to popup a message box.
While the message box is displayed, it seems that Excel is locked up and not
redrawing its surface until message box control returns to it, that is,
until the message box is acknowledged.

I mention that my class is not a macro. It just accesses the Excel from
within an .NET Windows Application.

Any idea why MS Excel framwork does not get repaint while the message box is
shown?

Thanks,
Mircea

What happens if you drag the messagebox around? Will it be all white?

/Fredrik
 
Not at all. The Excel does not repaint and an image with the message box at
the previous position remains on the screen.
 
Mircea Pleteriu said:
Not at all. The Excel does not repaint and an image with the message box at
the previous position remains on the screen.

So you end up with 2 or more messageboxes? Can you attach a screen copy. I
know I had a problem like this a long time ago, I hope I can remeber the
solution.

/Fredrik
 
Mircea Pleteriu said:
Please find attached a screen shot.

I recognize this problem. I need to think before I can reply. BTW since your
code apparently is very small, can you send it as well. All I want is the
minimum amount of code that shows this problem.

/Fredrik
 
Here it is:

// Create instance of Excel application

this.excelApp = new Excel.ApplicationClass();

this.workbooks = this.excelApp.Workbooks;

// Open workbook with file

this.fileWorkbook = workbooks.Open(path,

Type.Missing, Type.Missing, Type.Missing, Type.Missing,

Type.Missing, Type.Missing, Type.Missing, Type.Missing,

Type.Missing, Type.Missing, Type.Missing, Type.Missing,

Type.Missing, Type.Missing);



// Get context menu

Office.CommandBarControls contextMenu =
this.excelApp.CommandBars["Cell"].Controls;

// Add item to menu

this.item =
(Office.CommandBarButton)contextMenu.Add(Office.MsoControlType.msoControlBut
ton, Type.Missing, Type.Missing, Type.Missing, true);

this.item.Caption = "MyNewItem";

this.item.BeginGroup = true;

this.item.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(ClickHandler
Method);




// Make instance of Excel application visible

this.excelApp.Visible = true;

Here is the ClickHandlerMethod's code

// Switch alerts off
this.excelApp.DisplayAlerts = false;

System.Windows.Forms.MessageBox.Show("Excel does not repaint!");
 
I would like to test this on my PC. Can you zip the project and send it to
me. My email address is
(e-mail address removed)

/Fredrik

Mircea Pleteriu said:
Here it is:

// Create instance of Excel application

this.excelApp = new Excel.ApplicationClass();

this.workbooks = this.excelApp.Workbooks;

// Open workbook with file

this.fileWorkbook = workbooks.Open(path,

Type.Missing, Type.Missing, Type.Missing, Type.Missing,

Type.Missing, Type.Missing, Type.Missing, Type.Missing,

Type.Missing, Type.Missing, Type.Missing, Type.Missing,

Type.Missing, Type.Missing);



// Get context menu

Office.CommandBarControls contextMenu =
this.excelApp.CommandBars["Cell"].Controls;

// Add item to menu

this.item =
(Office.CommandBarButton)contextMenu.Add(Office.MsoControlType.msoControlBut
ton, Type.Missing, Type.Missing, Type.Missing, true);

this.item.Caption = "MyNewItem";

this.item.BeginGroup = true;

this.item.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(ClickHandler
Method);




// Make instance of Excel application visible

this.excelApp.Visible = true;

Here is the ClickHandlerMethod's code

// Switch alerts off
this.excelApp.DisplayAlerts = false;

System.Windows.Forms.MessageBox.Show("Excel does not repaint!");



I recognize this problem. I need to think before I can reply. BTW since your
code apparently is very small, can you send it as well. All I want is the
minimum amount of code that shows this problem.

/Fredrik
 
Hi Mircea,

Try setting the ScreenUpdating property of the Excel Application object to
True before displaying any forms or messageboxes. I'm not sure why it would
be False, as it defaults to True. But explicitly setting it to True should
fix what you're seeing.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
Jake Marx said:
Hi Mircea,

Try setting the ScreenUpdating property of the Excel Application object to
True before displaying any forms or messageboxes. I'm not sure why it would
be False, as it defaults to True. But explicitly setting it to True should
fix what you're seeing.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

I.m not sure it will help but it's worth trying. I did a test where I set
this property to false. I then dragged other windows over Excel, both from
Excel and from other programs. Excel redraw as it should. I don't think this
command prevents Excel's main window from being redrawn although it prevents
updated values in cells to appear.

/Fredrik
 
Hi Mircea,

The picture you attached, together with the other symptoms you described, is
typical of Screenupdating not being reset from False to True, I'm assuming
that somewhere you disabled it.

Application.ScreenUpdating = True

Always ensure it is reset when your code terminates, sometimes gets
overlooked in error handling routines. Also need to reset to display a
MsgBox, or indeed any thing else that changes that you want your users to
see while your code is running.

Regards,
Peter T
 
I've set the ScreenUptating to true but no change. The same behaviour.
 
Do I have to set the parent of the message box to point to the Excel's main
window?
 
Hi Mircea,

Attaching files to this NG is frowned upon. I'm not much of a C# expert,
but I tried creating a simple C# winforms app that does what you're doing,
and I was unable to get Excel to refresh its display, too. I tried passing
Excel's handle to the Show method of the MessageBox class, and it didn't
help. You may want to try your question in a C# group to see if anyone has
had this problem when automating Excel from C#. Sorry!

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Mircea said:
Hi Jake,

Please find attached the solution with my very short windows app.
Maybe you'll get an idea about what's going wrong. The code is very
simple.

Thank you for any help,
Mircea

Jake Marx said:
Hi Mircea,

Try setting the ScreenUpdating property of the Excel Application
object to True before displaying any forms or messageboxes. I'm not
sure why it would be False, as it defaults to True. But explicitly
setting it to True should fix what you're seeing.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Mircea said:
Hi,

I'm developing a class which opens the MS Excel
and extend the context menu with a new item. When the item is
clicked all it does is to popup a message box.
While the message box is displayed, it seems that Excel is locked up
and not redrawing its surface until message box control returns to
it, that is, until the message box is acknowledged.

I mention that my class is not a macro. It just accesses the Excel
from within an .NET Windows Application.

Any idea why MS Excel framwork does not get repaint while the
message box is shown?

Thanks,
Mircea
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top