Workbook.Activate in Excel 2013

Add-in Express™ Support Service
That's what is more important than anything else

Workbook.Activate in Excel 2013
 
Albert Siagian




Posts: 86
Joined: 2012-05-25
Hello,

I have code as follows (Add-in Express 8.01)

Dim ci = AddinModule.CurrentInstance
Dim ExcelApp = ci.ExcelApp

ExcelApp.ScreenUpdating = False
Dim wb As Excel.Workbook = ExcelApp.ActiveWorkbook
ExcelApp.Workbooks.Add()
wb.Activate()
ExcelApp.ScreenUpdating = True

In XL 2010 32-bit, it works fine, that it activates original Workbook (i.e. Book1). However, in XL 2016 32-bit, it stays in the new Workbook (i.e. Book2). The only way to return to Book1, is not to use ScreenUpdating = False.

Any idea to solve this issue, as I need ScreenUpdating = False ?

Thanks
Albert
Posted 16 Jun, 2016 21:00:22 Top
Andrei Smolin


Add-in Express team


Posts: 14210
Joined: 2006-05-11
Hello Albert,

You can try activating that workbook after you set ExcelApp.ScreenUpdating = True.

Also note that ExcelApp.Workbooks.Add() creates two COM objects; both of them aren't released in your code. Your add-in may cause Excel hang in processes if the user or an application starts it programmatically. I strongly suggest that you check Why doesn’t Excel quit.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Jun, 2016 06:36:04 Top
Albert Siagian




Posts: 86
Joined: 2012-05-25
Hello Andrei,

Thanks for your reply. Activating Workbook after ScrenUpdating = True is the solution I am avoiding for, if possible, but looks like that is the only solution.

Also thanks for the advise regarding releasing COM objects, will check it out.

Regards
Albert
Posted 20 Jun, 2016 06:50:04 Top
Andrei Smolin


Add-in Express team


Posts: 14210
Joined: 2006-05-11
You are welcome.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Jun, 2016 07:06:12 Top