I built an excel addin that populates a worksheet with data from a database. I also add some style and block some rows and columns with FreezePanes.
worksheet.Activate();
worksheet.Application.ActiveWindow.FreezePanes = false;
worksheet.Application.ActiveWindow.SplitRow = 4;
worksheet.Application.ActiveWindow.SplitColumn = 11;
worksheet.Application.ActiveWindow.FreezePanes = true;
It all worked like a charm in excel 2010/2013, but I recently switched to excel 2016 (office 365), and since then I had problems with FreezePanes when my excel worksheet was not in the foreground. I searched the Internet, and the only thing I came across was that I can only harvest FreezePanes on the active sheet, I knew that - I already activated the sheet before installing FreezePanes. This worked in excel 2010, although physically my excel was not brought to the fore.
Office 365 Excel probably really wants my excel worksheet to be physically in the foreground, but it worksheet.Activate()doesn't help, and I also tried the following code:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName);
string caption = oExcel.Caption;
IntPtr handler = FindWindow(null, caption);
SetForegroundWindow(handler);
But that didn't work either. Can anyone help me with this?
To be clear: my excel version is 2016 version 2016 version (Build 7571.2109)
source
share