DMG Posted October 1, 2021 Share Posted October 1, 2021 I am new to AutoIt and am trying to create a program for my users to run. It opens a specified document in Microsoft Word, and then goes into File, Info, Inspect Document, which brings up Document Inspector. There are a series of checkboxes in the Document Inspector, and I need to uncheck some, and check others, but the initial state of the checkboxes varies from user to user. I know you can ControlCommand something to make sure it is checked, but it appears it needs a specific control ID (for example, "Button4" if working with buttons). I know about setting coord mode to window in AutoIt Window Info (x64), and have tried it both Spy++ Control Detection Logic both on and off. Unfortunately, the only thing that ever changes in this window are the mouse coordinates. While I could do a MouseClick, it would only toggle the checkbox, not set it to a specific state. Is there any way around something like that? If I can't automate it, the users will have to do it manually (and they don't want to). I hope I've posted this in the correct way. Link to comment Share on other sites More sharing options...
DMG Posted October 1, 2021 Author Share Posted October 1, 2021 Here's a screenshot with AutoIt Window Info. Only mouse coordinates (and ControlClick Coords) ever change. Link to comment Share on other sites More sharing options...
mLipok Posted October 1, 2021 Share Posted October 1, 2021 2️⃣4️⃣um. Check this: DMG and Earthshine 2 Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 2, 2021 Moderators Share Posted October 2, 2021 Moved to the appropriate forum. Moderation Team DMG 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Earthshine Posted October 2, 2021 Share Posted October 2, 2021 UIAutomation is the way DMG 1 My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
junkew Posted October 3, 2021 Share Posted October 3, 2021 (edited) What is your end goal? Word has an excellent object model that you can reach with Objcreate objcreate("word.application") Edited October 3, 2021 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
DMG Posted October 11, 2021 Author Share Posted October 11, 2021 Thank you all for the answers above, particularly @mLipok. I have been struggling to figure this out. I have done CTRL+W on all the elements of the Word dialogue box I want to ControlCommand, redlined them to each other, and created a spreadsheet that shows which elements are different from each other. However, I'm having difficulty figuring out how I translate that into the AutoIT script. For example, the only thing that really comes up differently (aside from names/titles) for each of the elements (see dialogue box with checks above) are these coordinates (for example): Class := <NetUICheckbox> controltype:= <UIA_CheckBoxControlTypeId>,<50002>, (0000C352) 2629;339;206;16. Each checkbox has all the same text, except for those two coordinates. I am very new to AutoIt and have been searching the internet, your links above, and the Help file, and can't seem to find exactly what I should do with the information SimpleSpy gave me on these elements. Any help would be appreciated! In particular, I'm wanting to make sure each of the checkboxes (see figure above) is either checked or unchecked, depending on the item. ControlCommand("Document Inspector", "", ____________________________________, "Check") Link to comment Share on other sites More sharing options...
junkew Posted October 12, 2021 Share Posted October 12, 2021 Your way out is so much easier with a vba macro (and if thats not allowed then with AutoIt objcreate word.application) https://office-watch.com/2018/saving-word-document-with-automatic-document-inspector/ seadoggie01 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
DMG Posted October 19, 2021 Author Share Posted October 19, 2021 Thank you, @junkew. I now have a Word macro that saves the document the way I want. However, I need to combine the AutoIt script with the Word macro, and all the examples I'm finding involve opening a specific Word document. I need the AutoIt script to run (which opens a user-specified document), and then the Word macro to run inside that open document (which will always be different). For example, this is what I have so far. At the point where I have "xxx," I need it to activate the Word document the user has opened, and run the Word macro (which we will make available to the users in advance) on the open document. The macro will finish out what the users need to do (i.e., after metadata removal, save the document, and bring up a message telling them what to do next). Even better would be if I could run the macro, and then do what the users need to do next. AutoItSetOption("MouseCoordMode", 0) AutoItSetOption("SendKeyDelay", 10) Opt("WinTitleMatchMode", 2) #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form=C:\Program Files (x86)\AutoIt3\koda_1.7.3.0\Forms\IP Form.kxf Global $Form1 = GUICreate("Remove Metadata and Lock Version as Record", 565, 364, 192, 124) Global $Label1 = GUICtrlCreateLabel("NOTE:", 16, 16, 59, 27) GUICtrlSetFont(-1, 12, 400, 0, "Arial Black") Global $Label2 = GUICtrlCreateLabel("1. Document must be a WORD document and must be CLOSED.", 30, 50, 454, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label3 = GUICtrlCreateLabel("2. Word must be CLOSED.", 30, 84, 193, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label4 = GUICtrlCreateLabel("3. DeskSite must be open and document should not show as checked out.", 30, 118, 513, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label5 = GUICtrlCreateLabel("DeskSite Document Number:", 74, 162, 207, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Input1 = GUICtrlCreateInput("", 288, 160, 121, 26) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label6 = GUICtrlCreateLabel("If all criteria met and document number filled in, hit Continue.", 103, 204, 416, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label7 = GUICtrlCreateLabel("Otherwise, close this box with the X.", 103, 232, 251, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label8 = GUICtrlCreateLabel("After hitting Continue, do not use your keyboard or mouse until prompted.", 30, 288, 505, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Button1 = GUICtrlCreateButton("Continue", 233, 320, 99, 33) GUICtrlSetFont(-1, 12, 400, 0, "Arial") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Global $DeskSiteNum = GUICtrlRead($Input1) WinClose("Remove Metadata and Lock Version as Record") Sleep(300) WinActivate("iManage Work") Sleep(900) MouseClick("Primary", 139, 46, 1, 0) Sleep(900) MouseClick("Primary", 102, 84, 1, 0) Sleep(900) WinWaitActive("Search Dialog", "", 30000) WinActivate("Search Dialog") Sleep(600) ControlClick("Search Dialog", "", 331) Sleep(600) ControlClick("Search Dialog", "", 300) Sleep(300) Send($DeskSiteNum) Sleep(600) Send ("{ENTER}") Sleep(5000) WinActivate("iManage Work") Sleep(300) MouseClick("Primary", 215, 49, 1, 0) Sleep(900) MouseClick("Primary", 256, 117, 1, 0) Sleep(900) MouseClick("Primary", 340, 175, 1, 0) Sleep(900) WinWaitActive("New Version Profile", "PCR1",30000) Sleep(600) WinActivate("New Version Profile") ControlClick("New Version Profile", "", 391) Sleep(300) Send("{HOME}") Sleep(300) Send("FILED: ", 10) Sleep(300) ControlClick("New Version Profile", "", 5310) Sleep(300) Send("{HOME}") Sleep(300) Send("Metadata removed and version declared as Record. ", 10) ControlClick("New Version Profile", "", 1) xxx EndSwitch WEnd Link to comment Share on other sites More sharing options...
junkew Posted October 19, 2021 Share Posted October 19, 2021 (edited) https://www.autoitscript.com/autoit3/docs/functions/ObjGet.htm Attach to running word.application Get activedocument Set the properties similar like you would do in vba There is no need to use click commands from AutoIt And i think you can put vba macros in a shared document or template so its allways available when word is open but approach with AutoIt and objget should work for sure. Edited October 19, 2021 by junkew DMG 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
DMG Posted October 25, 2021 Author Share Posted October 25, 2021 (edited) I am very close now, thanks to all your help above. I have a script that when I run in pieces, as I create it, it works. However, when I run it all at once, it errors out in the Func Example(). Can you see where I am going wrong with it? AutoItSetOption("MouseCoordMode", 0) AutoItSetOption("SendKeyDelay", 10) Opt("WinTitleMatchMode", 2) #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Remove Metadata and Lock Version as Record", 632, 455, 192, 124) Global $Label1 = GUICtrlCreateLabel("NOTE:", 8, 16, 59, 27) GUICtrlSetFont(-1, 12, 400, 0, "Arial Black") Global $Label2 = GUICtrlCreateLabel("1. Document must be a WORD document and must be CLOSED.", 17, 56, 458, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label3 = GUICtrlCreateLabel("2. Word must be CLOSED. DeskSite should be open.", 17, 96, 458, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label4 = GUICtrlCreateLabel("3. DeskSite must be maximized, and document should not show as checked out.", 17, 136, 600, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label5 = GUICtrlCreateLabel("DeskSite Document Number:", 73, 178, 207, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Input1 = GUICtrlCreateInput("", 281, 176, 121, 26) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label6 = GUICtrlCreateLabel("If all criteria met and document number filled in, hit Continue.", 119, 224, 416, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label7 = GUICtrlCreateLabel("Otherwise, close this box with the X.", 169, 256, 251, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label8 = GUICtrlCreateLabel("After hitting Continue, do not use your keyboard or mouse until prompted.", 119, 296, 505, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label9 = GUICtrlCreateLabel("NOTE: There are some wait times programmed into this macro,", 169, 336, 442, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label10 = GUICtrlCreateLabel("but not more than 15 seconds at at time.", 222, 360, 280, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Button1 = GUICtrlCreateButton("Continue", 304, 416, 75, 25) GUICtrlSetFont(-1, 12, 400, 0, "Arial") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Global $DeskSiteNum = GUICtrlRead($Input1) WinClose("Remove Metadata and Lock Version as Record") Sleep(300) WinActivate("iManage Work") Sleep(900) MouseClick("Primary", 139, 46, 1, 0) Sleep(900) MouseClick("Primary", 102, 84, 1, 0) Sleep(900) WinWaitActive("Search Dialog", "", 30000) WinActivate("Search Dialog") Sleep(600) ControlClick("Search Dialog", "", 331) Sleep(600) ControlClick("Search Dialog", "", 300) Sleep(300) Send($DeskSiteNum) Sleep(600) Send ("{ENTER}") Sleep(5000) WinActivate("iManage Work") Sleep(300) MouseClick("Primary", 215, 49, 1, 0) Sleep(900) MouseClick("Primary", 256, 117, 1, 0) Sleep(900) MouseClick("Primary", 340, 175, 1, 0) Sleep(900) WinWaitActive("New Version Profile", "PCR1",30000) Sleep(600) WinActivate("New Version Profile") ControlClick("New Version Profile", "", 391) Sleep(300) Send("{HOME}") Sleep(300) Send("FILED: ", 10) Sleep(300) ControlClick("New Version Profile", "", 5310) Sleep(300) Send("{HOME}") Sleep(300) Send("Metadata removed and version declared as Record. ", 10) ControlClick("New Version Profile", "", 1) Sleep(15000) Example() Func Example() Local $oWord = ObjGet("", "Word.Application") If @error Then MsgBox($MB_SYSTEMMODAL, "", "Word File Test" & @CRLF & "Error getting an active Word Object. Error code: " & Hex(@error, 😎 Return False EndIf $oWord.Visible = 1 $oWord.Run("InspectTheDocument") EndFunc WinActivate("Word") Sleep(900) Send("{F12}") WinWaitActive("Save As Options") WinActivate("Save As Options") ControlClick("Save As Options", "", 215) Sleep(900) ControlClick("Save As Options", "", 1) Sleep(15000) WinActivate("Word") Sleep(300) MouseClick("Primary", 1905, 23, 1, 0) Sleep(15000) WinActivate("iManage Work") Sleep(900) MouseClick("Right", 682, 190, 1, 0) Sleep(900) MouseClick("Primary", 739, 454, 1, 0) WinWaitActive("iManage", "You are about to") Sleep(300) WinActivate("iManage", "You are about to") ControlClick("iManage", "You are about to", 203) MsgBox(0, "NOTE", "Once you see a record icon next to the version, the macro is finished. Previous and future versions will not be affected.") EndSwitch WEnd Edited October 25, 2021 by DMG Link to comment Share on other sites More sharing options...
Earthshine Posted October 25, 2021 Share Posted October 25, 2021 (edited) yeah, static timing using SLEEP is usually a culprit. it's a timing issue no doubt. also when you post code use code tags <> in the control bar above so it looks like this below: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Remove Metadata and Lock Version as Record", 632, 455, 192, 124) Global $Label1 = GUICtrlCreateLabel("NOTE:", 8, 16, 59, 27) GUICtrlSetFont(-1, 12, 400, 0, "Arial Black") Global $Label2 = GUICtrlCreateLabel("1. Document must be a WORD document and must be CLOSED.", 17, 56, 458, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label3 = GUICtrlCreateLabel("2. Word must be CLOSED. DeskSite should be open.", 17, 96, 458, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label4 = GUICtrlCreateLabel("3. DeskSite must be maximized, and document should not show as checked out.", 17, 136, 600, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label5 = GUICtrlCreateLabel("DeskSite Document Number:", 73, 178, 207, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Input1 = GUICtrlCreateInput("", 281, 176, 121, 26) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label6 = GUICtrlCreateLabel("If all criteria met and document number filled in, hit Continue.", 119, 224, 416, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label7 = GUICtrlCreateLabel("Otherwise, close this box with the X.", 169, 256, 251, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label8 = GUICtrlCreateLabel("After hitting Continue, do not use your keyboard or mouse until prompted.", 119, 296, 505, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label9 = GUICtrlCreateLabel("NOTE: There are some wait times programmed into this macro,", 169, 336, 442, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label10 = GUICtrlCreateLabel("but not more than 15 seconds at at time.", 222, 360, 280, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Button1 = GUICtrlCreateButton("Continue", 304, 416, 75, 25) GUICtrlSetFont(-1, 12, 400, 0, "Arial") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Global $DeskSiteNum = GUICtrlRead($Input1) WinClose("Remove Metadata and Lock Version as Record") Sleep(300) WinActivate("iManage Work") Sleep(900) MouseClick("Primary", 139, 46, 1, 0) Sleep(900) MouseClick("Primary", 102, 84, 1, 0) Sleep(900) WinWaitActive("Search Dialog", "", 30000) WinActivate("Search Dialog") Sleep(600) ControlClick("Search Dialog", "", 331) Sleep(600) ControlClick("Search Dialog", "", 300) Sleep(300) Send($DeskSiteNum) Sleep(600) Send ("{ENTER}") Sleep(5000) WinActivate("iManage Work") Sleep(300) MouseClick("Primary", 215, 49, 1, 0) Sleep(900) MouseClick("Primary", 256, 117, 1, 0) Sleep(900) MouseClick("Primary", 340, 175, 1, 0) Sleep(900) WinWaitActive("New Version Profile", "PCR1",30000) Sleep(600) WinActivate("New Version Profile") ControlClick("New Version Profile", "", 391) Sleep(300) Send("{HOME}") Sleep(300) Send("FILED: ", 10) Sleep(300) ControlClick("New Version Profile", "", 5310) Sleep(300) Send("{HOME}") Sleep(300) Send("Metadata removed and version declared as Record. ", 10) ControlClick("New Version Profile", "", 1) Sleep(15000) Example() Func Example() Local $oWord = ObjGet("", "Word.Application") If @error Then MsgBox($MB_SYSTEMMODAL, "", "Word File Test" & @CRLF & "Error getting an active Word Object. Error code: " & Hex(@error, 😎 Return False EndIf $oWord.Visible = 1 $oWord.Run("InspectTheDocument") EndFunc WinActivate("Word") Sleep(900) Send("{F12}") WinWaitActive("Save As Options") WinActivate("Save As Options") ControlClick("Save As Options", "", 215) Sleep(900) ControlClick("Save As Options", "", 1) Sleep(15000) WinActivate("Word") Sleep(300) MouseClick("Primary", 1905, 23, 1, 0) Sleep(15000) WinActivate("iManage Work") Sleep(900) MouseClick("Right", 682, 190, 1, 0) Sleep(900) MouseClick("Primary", 739, 454, 1, 0) WinWaitActive("iManage", "You are about to") Sleep(300) WinActivate("iManage", "You are about to") ControlClick("iManage", "You are about to", 203) MsgBox(0, "NOTE", "Once you see a record icon next to the version, the macro is finished. Previous and future versions will not be affected.") EndSwitch WEnd Edited October 25, 2021 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
DMG Posted October 25, 2021 Author Share Posted October 25, 2021 Thanks for the tip about posting code! As for the code I did post; it shouldn't have had a smiley face in it. I am posting that part of it again. Sleep(15000) Example() Func Example() Local $oWord = ObjGet("", "Word.Application") If @error Then MsgBox($MB_SYSTEMMODAL, "", "Word File Test" & @CRLF & "Error getting an active Word Object. Error code: " & Hex(@error, 8) Return False EndIf $oWord.Visible = 1 $oWord.Run("InspectTheDocument") EndFunc WinActivate("Word") So, any ideas why it errored out? I am so new to AutoIt that I don't even know what @error is; I copied that from internet research. The pieces of the code (above) work when run independently, but when run all together, I get that error noted in the code of this post. Link to comment Share on other sites More sharing options...
DMG Posted October 25, 2021 Author Share Posted October 25, 2021 Is it possible it would work without this? If @error Then MsgBox($MB_SYSTEMMODAL, "", "Word File Test" & @CRLF & "Error getting an active Word Object. Error code: " & Hex(@error, 8) Return False EndIf Link to comment Share on other sites More sharing options...
DMG Posted October 25, 2021 Author Share Posted October 25, 2021 Wow, that did work. So I ended up with this, but I will have to test it on different machines. If anyone wants to point anything out to me, I appreciate the help! expandcollapse popupAutoItSetOption("MouseCoordMode", 0) AutoItSetOption("SendKeyDelay", 10) Opt("WinTitleMatchMode", 2) #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Remove Metadata and Lock Version as Record", 632, 455, 192, 124) Global $Label1 = GUICtrlCreateLabel("NOTE:", 8, 16, 59, 27) GUICtrlSetFont(-1, 12, 400, 0, "Arial Black") Global $Label2 = GUICtrlCreateLabel("1. Document must be a WORD document and must be CLOSED.", 17, 56, 458, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label3 = GUICtrlCreateLabel("2. Word must be CLOSED. DeskSite should be open.", 17, 96, 458, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label4 = GUICtrlCreateLabel("3. DeskSite must be maximized, and document should not show as checked out.", 17, 136, 600, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label5 = GUICtrlCreateLabel("DeskSite Document Number:", 73, 178, 207, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Input1 = GUICtrlCreateInput("", 281, 176, 121, 26) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label6 = GUICtrlCreateLabel("If all criteria met and document number filled in, hit Continue.", 119, 224, 416, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label7 = GUICtrlCreateLabel("Otherwise, close this box with the X.", 169, 256, 251, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label8 = GUICtrlCreateLabel("After hitting Continue, do not use your keyboard or mouse until prompted.", 119, 296, 505, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label9 = GUICtrlCreateLabel("NOTE: There are some wait times programmed into this macro,", 169, 336, 442, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label10 = GUICtrlCreateLabel("but not more than 15 seconds at at time.", 222, 360, 280, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Button1 = GUICtrlCreateButton("Continue", 304, 416, 75, 25) GUICtrlSetFont(-1, 12, 400, 0, "Arial") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Global $DeskSiteNum = GUICtrlRead($Input1) WinClose("Remove Metadata and Lock Version as Record") Sleep(300) WinActivate("iManage Work") Sleep(900) MouseClick("Primary", 139, 46, 1, 0) Sleep(900) MouseClick("Primary", 102, 84, 1, 0) Sleep(900) WinWaitActive("Search Dialog", "", 30000) WinActivate("Search Dialog") Sleep(600) ControlClick("Search Dialog", "", 331) Sleep(600) ControlClick("Search Dialog", "", 300) Sleep(300) Send($DeskSiteNum) Sleep(600) Send ("{ENTER}") Sleep(5000) WinActivate("iManage Work") Sleep(300) MouseClick("Primary", 215, 49, 1, 0) Sleep(900) MouseClick("Primary", 256, 117, 1, 0) Sleep(900) MouseClick("Primary", 340, 175, 1, 0) Sleep(900) WinWaitActive("New Version Profile", "PCR1",30000) Sleep(600) WinActivate("New Version Profile") ControlClick("New Version Profile", "", 391) Sleep(300) Send("{HOME}") Sleep(300) Send("FILED: ", 10) Sleep(300) ControlClick("New Version Profile", "", 5310) Sleep(300) Send("{HOME}") Sleep(300) Send("Metadata removed and version declared as Record. ", 10) ControlClick("New Version Profile", "", 1) Sleep(15000) Example() Func Example() Local $oWord = ObjGet("", "Word.Application") $oWord.Visible = 1 $oWord.Run("InspectTheDocument") EndFunc WinActivate("Word") Sleep(900) Send("{F12}") WinWaitActive("Save As Options") WinActivate("Save As Options") ControlClick("Save As Options", "", 215) Sleep(900) ControlClick("Save As Options", "", 1) Sleep(15000) WinActivate("Word") Sleep(300) MouseClick("Primary", 1905, 23, 1, 0) Sleep(15000) WinActivate("iManage Work") Sleep(900) MouseClick("Right", 682, 190, 1, 0) Sleep(900) MouseClick("Primary", 739, 454, 1, 0) WinWaitActive("iManage", "You are about to") Sleep(300) WinActivate("iManage", "You are about to") ControlClick("iManage", "You are about to", 203) MsgBox(0, "NOTE", "Once you see a record icon next to the version, the macro is finished. Previous and future versions will not be affected.") EndSwitch WEnd Link to comment Share on other sites More sharing options...
junkew Posted October 26, 2021 Share Posted October 26, 2021 (edited) I would use More functions per screen area you are handling so you know next year still what you are doing. Make the functionnames more with your functional intent Per function makes your life easier to debug Put those functions in a region as when it works you probably won''t look frequently at it Add some comments about which element you try to click Add a simply mySync that initially just wraps away the sleep but later you can improve then on syncing on title of screen cursor hourglass ..... Something like below expandcollapse popupAutoItSetOption("MouseCoordMode", 0) AutoItSetOption("SendKeyDelay", 10) Opt("WinTitleMatchMode", 2) #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Remove Metadata and Lock Version as Record", 632, 455, 192, 124) Global $Label1 = GUICtrlCreateLabel("NOTE:", 8, 16, 59, 27) GUICtrlSetFont(-1, 12, 400, 0, "Arial Black") Global $Label2 = GUICtrlCreateLabel("1. Document must be a WORD document and must be CLOSED.", 17, 56, 458, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label3 = GUICtrlCreateLabel("2. Word must be CLOSED. DeskSite should be open.", 17, 96, 458, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label4 = GUICtrlCreateLabel("3. DeskSite must be maximized, and document should not show as checked out.", 17, 136, 600, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label5 = GUICtrlCreateLabel("DeskSite Document Number:", 73, 178, 207, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Input1 = GUICtrlCreateInput("", 281, 176, 121, 26) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label6 = GUICtrlCreateLabel("If all criteria met and document number filled in, hit Continue.", 119, 224, 416, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label7 = GUICtrlCreateLabel("Otherwise, close this box with the X.", 169, 256, 251, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label8 = GUICtrlCreateLabel("After hitting Continue, do not use your keyboard or mouse until prompted.", 119, 296, 505, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label9 = GUICtrlCreateLabel("NOTE: There are some wait times programmed into this macro,", 169, 336, 442, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Label10 = GUICtrlCreateLabel("but not more than 15 seconds at at time.", 222, 360, 280, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Button1 = GUICtrlCreateButton("Continue", 304, 416, 75, 25) GUICtrlSetFont(-1, 12, 400, 0, "Arial") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Global $DeskSiteNum = GUICtrlRead($Input1) WinClose("Remove Metadata and Lock Version as Record") mySync(300) handleScreen_iManage_WorkPart1() handleScreen_Search_Dialog() handleScreen_iManage_WorkPart2() handleScreen_New_Version_Profile() activateWordApplication() activateSaveAsOptionsDialog() handleScreen_Save_As_Options() ;~TODO:handleScreenWord() WinActivate("Word") mySync(300) MouseClick("Primary", 1905, 23, 1, 0) mySync(15000) ;~TODO:handleScreen_iManage_WorkPart3() WinActivate("iManage Work") mySync(900) MouseClick("Right", 682, 190, 1, 0) mySync(900) MouseClick("Primary", 739, 454, 1, 0) ;~TODO:handleScreen_you_ara_about_to() WinWaitActive("iManage", "You are about to") mySync(300) WinActivate("iManage", "You are about to") ControlClick("iManage", "You are about to", 203) MsgBox(0, "NOTE", "Once you see a record icon next to the version, the macro is finished. Previous and future versions will not be affected.") EndSwitch WEnd #region screen helper functions func mySync(ms = 300) mySync(ms) EndFunc func handleScreen_iManage_WorkPart1() WinActivate("iManage Work") mySync(900) MouseClick("Primary", 139, 46, 1, 0) mySync(900) MouseClick("Primary", 102, 84, 1, 0) mySync(900) EndFunc func handleScreen_Search_Dialog() WinWaitActive("Search Dialog", "", 30000) WinActivate("Search Dialog") mySync(600) ControlClick("Search Dialog", "", 331) mySync(600) ControlClick("Search Dialog", "", 300) mySync(300) Send($DeskSiteNum) mySync(600) Send ("{ENTER}") mySync(5000) EndFunc func handleScreen_iManage_WorkPart2() WinActivate("iManage Work") mySync(300) MouseClick("Primary", 215, 49, 1, 0) mySync(900) MouseClick("Primary", 256, 117, 1, 0) mySync(900) MouseClick("Primary", 340, 175, 1, 0) mySync(900) endFunc func handleScreen_New_Version_Profile() WinWaitActive("New Version Profile", "PCR1",30000) mySync(600) WinActivate("New Version Profile") ControlClick("New Version Profile", "", 391) mySync(300) Send("{HOME}") mySync(300) Send("FILED: ", 10) mySync(300) ControlClick("New Version Profile", "", 5310) mySync(300) Send("{HOME}") mySync(300) Send("Metadata removed and version declared as Record. ", 10) ControlClick("New Version Profile", "", 1) mySync(15000) EndFunc Func activateWordApplication() Local $oWord = ObjGet("", "Word.Application") $oWord.Visible = 1 $oWord.Run("InspectTheDocument") EndFunc Func activateSaveAsOptionsDialog() WinActivate("Word") mySync(900) Send("{F12}") EndFunc func handleScreen_Save_As_Options() WinWaitActive("Save As Options") WinActivate("Save As Options") ControlClick("Save As Options", "", 215) mySync(900) ControlClick("Save As Options", "", 1) mySync(15000) EndFunc #EndRegion I checked UIAutomation and that can detect your checkboxes however UIAutomation is seen by many people as more difficult but there are many examples in forum if you search for https://www.autoitscript.com/forum/search/?&q=uia automation&search_and_or=and&sortby=relevancy Edited October 26, 2021 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets 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