SlackerAl Posted March 20, 2018 Share Posted March 20, 2018 (edited) I have been trying to embed an empty excel sheet into a GUI... Running on Win10 In the following code, un-commenting line 116 leads to AutoIT pausing in the background. Any thoughts? I've tried stripping it to the absolute minimum (i.e. remove error trapping etc. same result). expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Local $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") Local $FileName = @ScriptDir & "\Book1.xlsx" Local $oExcelDoc $oExcelDoc = ObjGet($FileName) GUICreate("Embed Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $WS_MINIMIZEBOX + $WS_SYSMENU + $WS_CLIPCHILDREN) GUISetOnEvent($GUI_EVENT_CLOSE, "MenuExit") ; This line causes AutoIT to background and pause/hang ;GUICtrlCreateObj($oExcelDoc, -1, -1) GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func MenuExit() If IsObj($oExcelDoc) Then $oExcelDoc.Close(0) GUIDelete() Exit EndFunc Func MyErrFunc() ;from https://www.autoitscript.com/forum/topic/31963-excel-window-in-a-gui/ $HexNumber=hex($oMyError.number,8) Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) Endfunc Edit: Sorry, I should add, you need to create a blank excel file in the script area and call it Book1.xlsx Edited March 20, 2018 by SlackerAl Additional information: Create excel file Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
SlackerAl Posted March 20, 2018 Author Share Posted March 20, 2018 Additional comments / thoughts: If this can be done without having the empty excel file, that would be great. When run, you can see that excel starts and runs (process list), but never becomes visible. Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
SlackerAl Posted March 21, 2018 Author Share Posted March 21, 2018 Is anyone able to run this with the critical line uncommented? Thanks. Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
Andreik Posted March 21, 2018 Share Posted March 21, 2018 How many rows/columns do you have in your excel? Probably it's just a slow load if you have a lot of data. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
SlackerAl Posted March 21, 2018 Author Share Posted March 21, 2018 The file is empty. I'm just seeing what it takes to embed excel into an AutoIt GUI. Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
water Posted March 21, 2018 Share Posted March 21, 2018 Use GUICtrlCreateObj to embed an application using an ActiveX control. The example script works for IE. I once tried MS Word but the result didn't convince me My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted March 21, 2018 Share Posted March 21, 2018 Something like this (tested with Excel 2017): expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> $FileName = @ScriptDir & '\book1.xlsx' If Not FileExists($FileName) Then MsgBox(0, "ERROR", "File not found") Exit EndIf ;Basic GUI $oExcelDoc = ObjGet($FileName) ; Get an excel Object from an existing filename If IsObj($oExcelDoc) Then $mainGUI = GUICreate("viewer", @DesktopWidth - 50, @DesktopHeight - 150, 10, 10, $WS_MINIMIZEBOX + $WS_SYSMENU + $WS_CLIPCHILDREN) $GUI_ActiveX = GUICtrlCreateObj($oExcelDoc, 10, 70, @DesktopWidth - 75, @DesktopHeight - 260) Else MsgBox(0, "", "failed") EndIf ;------------------ ;Turns off all command bars in excel to prevent user from making changes For $Bar In $oExcelDoc.CommandBars If $Bar.Enabled = True Then $Bar.Enabled = False If $Bar.Visible = True Then $Bar.Visible = False Next $oExcelDoc.Application.DisplayFormulaBar = False $oExcelDoc.Application.CommandBars("Shadow Settings").Visible = False $oExcelDoc.Application.DisplayScrollBars = True $oExcelDoc.Application.DisplayStatusBar = False GUISetState() ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($mainGUI) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Andreik Posted March 21, 2018 Share Posted March 21, 2018 Works too with Excel 2013 $oExcelDoc = ObjGet(@ScriptDir & '\test.xlsx') $hMain = GUICreate("Test", 400, 400) GUICtrlCreateObj($oExcelDoc, 0, 0, 400, 400) GUISetState(@SW_SHOW, $hMain) Do Sleep(10) Until GUIGetMsg() = -3 $oExcelDoc = 0 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
SlackerAl Posted March 21, 2018 Author Share Posted March 21, 2018 Hmmm, same problem for both of those. I have Office 365, which lists the application as Excel 2016. I'm guessing it no longer works as an embedded activex. I can see the excel process start in task manager and after I eventually kill it, if I open excel it shows the test file as not having saved correctly and asks if I would like to recover it - so excel has actually started and opened the file.... but nothing to see on the screen. Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
water Posted March 21, 2018 Share Posted March 21, 2018 (edited) Seems to be a problem with Office 365 No Office 365 here, so I can't offer any more assistance regarding this issue Edited March 21, 2018 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now