Jump to content

problem starting excel with add-in


 Share

Recommended Posts

I have an issue when starting Excel with the following code

#include <Excel.au3>
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

GUICreate("Excel Test", 600, 440)
GUISetOnEvent($GUI_EVENT_CLOSE, "MenuExit")
GUISetState(@SW_SHOW)

; Create application object
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox(0, "Excel UDF: _Excel_RangeFind Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; sit here forever with an option to react every 10ms
While 1
  Sleep(10)
WEnd

Exit

Func MenuExit()
    
  GUIDelete()
    Exit

EndFunc

If the Excel is a standard install, everything is OK. If Excel has the Kutools add-in (https://www.extendoffice.com/product/kutools-for-excel.html) installed and active the excel process runs (and is visible in task manager until killed), but it never displays. Disabling the add-in restores normal functionality.

If I add some additional code to interact with the excel application then still nothing happens if the add-in is active. However, if Excel is started first and then the AutoIt code is run, it is able to interact with the Excel session as normal.

Summary: The Excel add-in Kutools prevents excel being started with the _Excel_Open() command from AutoIt. Any AutoIt side work-arounds for this?

Edited by SlackerAl

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

When an instance of Excel is already running, then _Excel_Open connects to this instance. Else a new Excel instance is started.

When a new instance gets started how far does _Excel_Open get? Means, does it hang on line

$oExcel = ObjCreate("Excel.Application")

 

Another idea:

When no Excel process exists (function ProcessExists), then use Run or Shellexecute to start Excel, wait a bit and then call _Excel_Open to connect to this instance.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

It completes that line, if I add a MsgBox call to the next line, then I see the message box OK, but the Excel does not show up. Equally, my empty GUI window is visible and reactive to its close event. So the AutoIt process is still good, it's just Excel does not complete its launch. Perhaps this is another Office 365 feature...

I agree that I could do a more complicated launch of Excel, I guess I was just hoping for a lazier solution :-)

 

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

Do you get alerts when you run:

Local $oExcel = _Excel_Open(Default, True)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I'm guessing there is some sort of conflict on start up between the add-in and the _Excel_Open (is there a time out requirement for the start-up?).

Edited by SlackerAl

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

We once had similar problems with a Word add-in. The only solution was to deactivate the add-in :(

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Two different methods:

1. This method requires #RequireAdmin at the top of your script, by default LoadBehavior is set to 3, this won't allow you to load the Add-in, it needs to be changed to 2
More Info: https://docs.microsoft.com/en-us/visualstudio/vsto/registry-entries-for-vsto-add-ins?view=vs-2017#LoadBehavior

#RequireAdmin
RegWrite("HKLM\SOFTWARE\Microsoft\Office\Excel\AddIns\DeTong.KTELoader", "LoadBehavior", "REG_DWORD", 2) ;~ Enable Unload Kutools for Excel 18.00 at Startup
Local $oExcel = _Excel_Open()
For $i = 1 To $oExcel.COMAddIns.Count
    If $oExcel.COMAddIns($i).Description = "Kutools for Excel  18.00" Then
        $oExcel.COMAddIns($i).Connect = True
        ExitLoop
    EndIf
Next
RegWrite("HKLM\SOFTWARE\Microsoft\Office\Excel\AddIns\DeTong.KTELoader", "LoadBehavior", "REG_DWORD", 3) ;~ Enable Always Load Kutools for Excel 18.00 at Startup

2. Without #RequireAdmin you will need to delete the following registry value manually :"HKLM\SOFTWARE\Microsoft\Office\Excel\AddIns\DeTong.KTELoader", "LoadBehavior"
You will then use HKCU LoadBehavior to load the Add-in:

RegWrite("HKCU\SOFTWARE\Microsoft\Office\Excel\AddIns\DeTong.KTELoader", "LoadBehavior", "REG_DWORD", 2) ;~ Enable Unload Kutools for Excel 18.00
Local $oExcel = _Excel_Open()
For $i = 1 To $oExcel.COMAddIns.Count
    If $oExcel.COMAddIns($i).Description = "Kutools for Excel  18.00" Then
        $oExcel.COMAddIns($i).Connect = True
        ExitLoop
    EndIf
Next
RegWrite("HKCU\SOFTWARE\Microsoft\Office\Excel\AddIns\DeTong.KTELoader", "LoadBehavior", "REG_DWORD", 3) ;~ Enable Always Load Kutools for Excel 18.00 at Startup

We change the LoadBehavior right after loading the Add-on that will allow you to open Excel outside the Gui with the Add-in loaded on start-up.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...