Jump to content

Recommended Posts

Posted

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.

Posted

Here's a screenshot with AutoIt Window Info.  Only mouse coordinates (and ControlClick Coords) ever change.

Document Inspector Screenshot.PNG

Posted

:welcome:2️⃣:ILA2:4️⃣um.

Check this:

 

 

 

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 Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

  • 2 weeks later...
Posted

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")
 

Posted

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

Posted (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 by junkew
Posted (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 by DMG
Posted (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:

#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 by Earthshine

My resources are limited. You must ask the right questions

 

Posted

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.

Posted

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!

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")
               $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

 

Posted (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

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")
            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 by junkew

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...