HarishIyer Posted April 10, 2019 Share Posted April 10, 2019 (edited) HI Guys, I got the below code from autoit . It basically embeds a blank word in a gui. expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") Main() Func Main() Local $oWordApp = ObjCreate("Word.Application") Local $oWord = ObjCreate("Word.Document") $oWord.Activate Local $oWordEvent = ObjEvent($oWord, "WordEvent") Local $hWnd = GUICreate("Test", 800, 600, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN)) GUICtrlCreateObj($oWord, 10, 155, 300, 300) GUICtrlCreateTab(0, 0, 800, 600, $WS_CLIPSIBLINGS) GUICtrlCreateTabItem("Test1") GUICtrlCreateTabItem("Test2") GUICtrlCreateTabItem("") For $oCommandBar In $oWord.CommandBars If $oCommandBar.Type < 2 Then $oCommandBar.Enabled = False EndIf Next $oWord.CommandBars("Reviewing").Visible = False $oWord.CommandBars("Standard").Visible = False $oWord.CommandBars("Formatting").Visible = False $oWord.Activewindow.DisplayRulers = False $oWord.Activewindow.Split = False $oWord.Activewindow.SplitVertical = 0 $oWord.Application.DisplayScrollBars = False $oWord.Activewindow.View.Type = 6 $oWord.Activewindow.View.DisplayPageBoundaries GUISetState(@SW_SHOW, $hWnd) While WinExists($hWnd) Local $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then GUIDelete() WEnd EndFunc ; Main() Func WordEvent($sEvent) TrayTip("", "Event: " & $sEvent, 5) EndFunc Func MyErrFunc() Local $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); to check for after this function returns Endfunc I tried to change it for Excel as below. #include <GUIConstants.au3> #include <WindowsConstants.au3> $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") Main() Func Main() $VersionNumber = '3.01' Local $oExcel = ObjCreate("Excel.Application") $oExcel.Visible = 1 ; Let Excel show itself $oExcel.WorkBooks.Add Sleep(2000) Local $hWnd = GUICreate("aa" & $VersionNumber, @DesktopWidth , @DesktopHeight - 45,-1,-1, $WS_MINIMIZEBOX + $WS_SYSMENU + $WS_CLIPCHILDREN) GUICtrlCreateObj($oExcel, -1, -1, @DesktopWidth - 10, @DesktopHeight -75) GUISetState(@SW_SHOW, $hWnd) While WinExists($hWnd) Local $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then GUIDelete() WEnd EndFunc ; Main() Func MyErrFunc() Local $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); to check for after this function returns Endfunc It shows a COM Error. Can anyone help me in converting word.Document to excel. Many Thanks, Harish Edited April 10, 2019 by HarishIyer spleeing mistake Link to comment Share on other sites More sharing options...
water Posted April 10, 2019 Share Posted April 10, 2019 Check ObjEvent for how to add a COM error handler. 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...
HarishIyer Posted April 10, 2019 Author Share Posted April 10, 2019 Hi Water, Thanks for the reply. The error description is OK We intercepted a COM Error ! err.description is: err.windescription: Unspecified error err.number is: 80004005 err.lastdllerror is: 0 err.scriptline is: 15 err.source is: err.helpfile is: err.helpcontext is: Link to comment Share on other sites More sharing options...
water Posted April 10, 2019 Share Posted April 10, 2019 Details can be found here https://docs.microsoft.com/en-us/windows/desktop/seccrypto/common-hresult-values Unfortunately we have not enough error details (at the moment). Let me investigate how to get more info 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...
HarishIyer Posted April 10, 2019 Author Share Posted April 10, 2019 HI Water, I found objget to work but objcreate doesnt work! In the example you can see for word.application objget works but fails for excel Many Thanks, Harish Iyer 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