Question

Julius Bank on Wed, 21 May 2014 07:21:46


Hello,

Got the issue only with Excel 2013. In 2007 and 2010 this works fine. Also I'm on Windows 8.1

I have project c#, excel-addin. After loading my Com-Addin I'm hiding few workbooks and showing UserControl. In the task manager i see one instance "Microsoft Excel (32-bit)", after pressing Button program changes Ribbon menu, opens Excel Workbook(not hidden), making some changes. After all work done user should see Excel opened workbook, but instead he sees Excel blank window, and the workbook which need to show user is in different window. In the task manager i see: "Microsoft Excel (32-bit) (2)" it's like 2 different instances. I have tried adding at the end Workbook, Window - activate, not helping. I tried to add MessageBox'es to look what window or workbook activated and in all cases it was showing properly. When message box was shown user can see the workbook. but After Butoon3_Click ends(no my code anymore) excel by it self activates different window...  oh and by the why no errors shown.

Here is picture and code:

http://s30.postimg.org/4rqkjss7l/Untitled.png

As i mention before Excel 2007, 2010 has no such problems.

private void Button3_Click(System.Object sender, System.EventArgs e)
        {
             openS();
             //Globals.ThisAddIn.Application.Windows[SablonuGridas[SablonuGridas.Row, 1]].Activate();
             //((Excel._Workbook)Globals.ThisAddIn.Application.Workbooks[SablonuGridas[SablonuGridas.Row, 1]]).Activate();
        }

private void openS() { int i = 0; try { if (SablonuGridas.Row >= 0) { this.Visible = false; failas = Convert.ToString(SablonuGridas[SablonuGridas.Row, 1]); ThisAddIn.opend(direkt + failas, true, false); //here I open File addmeniu(); for (i = 1; i <= 10; i++) { try { ((Excel.Worksheet)Globals.ThisAddIn.Application.ActiveSheet).Shapes.Item(i).OnAction = ""; } catch {} } } else { MessageBox.Show("error!", ivvv, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Information); } }


public static void opend(string path, bool ll = true, bool bb = true)
        {
            Globals.ThisAddIn.Application.DisplayAlerts = false;
            Globals.ThisAddIn.Application.Workbooks.Open(path, ll, bb);
            Globals.ThisAddIn.Application.DisplayAlerts = true;
        }




Sponsored



Replies

Eugene Astafiev on Wed, 21 May 2014 15:49:29


Did you try to use the ScreenUpdating  property of the Application class?

Julius Bank on Wed, 21 May 2014 17:16:39


Did you try to use the ScreenUpdating  property of the Application class?

It's not a problem with screenUpdating, if you will look at screen i have uploaded: http://s30.postimg.org/4rqkjss7l/Untitled.png

You will see that i see that workbook, i need just activate it manually with mouse. The problem that Excel by itself "opens 2 instance" and activates blank or hidden workbook.

George Hua on Thu, 22 May 2014 06:05:35


Hi Julius,

The code you provided doesn’t work for me since below code doesn’t pass through runtime.

if (SablonuGridas.Row >= 0) {
                this.Visible = false;
                failas = Convert.ToString(SablonuGridas[SablonuGridas.Row, 1]);
                ThisAddIn.opend(direkt + failas, true, false); //here I open File
                addmeniu(); 
                for (i = 1; i <= 10; i++) {
                                try {
                                      ((Excel.Worksheet)Globals.ThisAddIn.Application.ActiveSheet).Shapes.Item(i).OnAction = "";
                                                                                                } catch {}
                                                                                }
                                                                } else {
                    MessageBox.Show("error!", ivvv, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                                                this.Visible = true;
                                                                }

I made a tested for you in Excel 2013.

I created a VSTO add-in for Excel 2013, type code below in a usercontrol that is host in the custom task pane:

private void button1_Click(object sender, EventArgs e)
        {
            openS();
        }

        private void openS()
        {
            try
            {
                //Globals.ThisAddIn.Application.ActiveWindow.Visible = false;
                opend("D:/1.xlsx");
                ((Excel.Worksheet)Globals.ThisAddIn.Application.ActiveSheet).Shapes.Item(1).OnAction = "";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        public static void opend(string path, bool ll = true, bool bb = true)
        {
            Globals.ThisAddIn.Application.DisplayAlerts = false;
            Globals.ThisAddIn.Application.Workbooks.Open(path, ll, bb);
            Globals.ThisAddIn.Application.DisplayAlerts = true;
        }

The code works fine for me and I would find two workbooks opened (one is current workbook, another is “1.xlsx”). They were in one Excel process:

You could find there was only one Excel process in details list of task manager.

If I hide current workbook before open a new workbook (this.Visible = False cannot be passed through runtime since this means current user control):

Globals.ThisAddIn.Application.ActiveWindow.Visible = false;

I would find there is one workbook and one Excel process in task manager. I can’t find a blank window.

Is there anything I missed?

Julius Bank on Thu, 22 May 2014 06:56:38



I forgot to mention My VSTO add-in created with 2007 Excel. If i will create on 2013 Excel, Users who has lower Excel wont be able to work on it, right? 3.5 FrameWork.

To make a bit more clear I made some changes by adding Message box'es.


for (i = 1; i <= 10; i++) {
						try {
							((Excel.Worksheet)Globals.ThisAddIn.Application.ActiveSheet).Shapes.Item(i).OnAction = "";
						} catch {}
					}
                    MessageBox.Show("here is my workbook");
private void Button3_Click(System.Object sender, System.EventArgs e)
        {
             openS();
             MessageBox.Show("the end of program!");
        }

here what i got:

http://s29.postimg.org/fqwnra6x3/excel2013.png

http://s28.postimg.org/wl2rznizh/excel2013_1.png

http://s9.postimg.org/lcle1tznj/excel2013_2.png

http://s30.postimg.org/sbjcpgvpd/excel2013_3.png

As you see after last message box displayed code ends with "}" mark, after 'by it self" activates blank/hidden workbook. By the way i got few hidden workbooks but I'm not activating them or touching.

Hope this helps to understand what happening.


Eugene Astafiev on Thu, 22 May 2014 07:30:38


Julius,

Nope, your add-in can support Office 2007 and above. Please take a look at the Running Solutions in Different Versions of Microsoft Office article for more information.

You need to set the target framework to .Net framework 4 and use PIAs that correspond to the lowest Office version you want to support (Outlook 2007 in your case).

George Hua on Thu, 22 May 2014 07:54:30


Hi Julius,

Eugene is correct.

You could create an Office 2013 solution with .NET Framework 4 or 4.5. This solution would be worked in Office 2007, Office 2010 and Office 2013.


We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Julius Bank on Thu, 22 May 2014 08:18:35


Hi Julius,

Eugene is correct.

You could create an Office 2013 solution with .NET Framework 4 or 4.5. This solution would be worked in Office 2007, Office 2010 and Office 2013.


We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.



Thank you for your both replys. This is not my main question or problem. You can check my last post to see where i got problems.

Julius Bank on Thu, 29 May 2014 07:44:10


I have solved this problem.

I've added Workbooks[].Activate after UserForm was closed. I have activated my Hidden workbook which user don't see. Don't know why but by activating hidden workbook, at the end i see workbook which user want to see.