Jump to content
albertmaathuis

Check state of word checkbox

Recommended Posts

albertmaathuis

Hi There,

 

I'm busy automating a proces in Word. the problem is that some of our users don't have the same checkboxes on or off in their environment.

I'm using word 2010 and word 2013.

When a word document is saved as a PDF document, sometimes the checkbox : "open file after publishing" is checked (so the PDF opens in Adobe)

Does anyone know a way how to read the state of a checkbox in a word window?

 

Share this post


Link to post
Share on other sites
water

Do you automate the saving of the word docoument as PDF?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SadBunny

This works for me in Word 2013:

$isChecked = ControlCommand("[CLASS:#32770]", "", "[CLASS:Button; INSTANCE:4]", "IsChecked"))

Don't know if the window class and checkbox control class are always the same, you'll have to check that for yourself.
Apart from that, there's a great Word UDF around. Look at the _Word* functions. _Word_DocSaveAs and _Word_Export seem interesting. I have never used it myself because I have a schijthekel aan MS Office, but it may be much less of a hassle using that precooked functionality for this automation project?


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
water

That was the reason for asking. It is much better and reliable to use the Word UDF and automate Word via COM than automating the GUI (as long as the methods and properties are exposed for COM).


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
caramen

If that does not work you can also reset all user word's profil like this:

Reg delet : HKEY_CURRENT_USER\Software\Microsoft\Office\<Your office version>\Word\Data

after a new run of word it will make it again ... yeah it s a bit brutal but this gonna work xD

 

if you are able to code complicated reg thing you can also save this key then delet it and then restore the key... that whould be also a solution.

Edited by caramen

My video tutorials : HERE ( In construction ) 

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
albertmaathuis

Thanks for the answers.

I think I have a old word.au3 (there is no _Word_Export function). The _Word_DocSaveAs doesn't seem to have the option to save as PDF.
@water: can you tell me please where i can find the latest version? 

@SadBunny: I tried to check the button with this command, but it doesn't seem to work. 

$isChecked=ControlCommand("[CLASS:#32770]", "", "[CLASS:Button; INSTANCE:1]", "Check","") 

also if the button is checked, the $isChecked=0 if I use:

$isChecked=ControlCommand("[CLASS:#32770]", "", "[CLASS:Button; INSTANCE:1]", "IsChecked","")

Share this post


Link to post
Share on other sites
water

The Word UDF comes with AutoIt. If you run 3.3.12.0 then you have the latest version of the UDF.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

BTW: The name of the function is _Word_DocExport.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
albertmaathuis

Thank you very much, this works great for me.

If everything was that simple....:)

Share this post


Link to post
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

  • Similar Content

    • stick3r
      By stick3r
      Hi, I have this script and I need to reset all checkboxes to UNCHECKED when button is pressed.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Global $Form = GUICreate("Checklist", 190, 407, 1233, 178) Global $text = "" Global $CheckBox GUICtrlCreateTab(1, 1, 190, 365) GUICtrlCreateTabItem("TAB 1") Global $InputCaseID1 = GUICtrlCreateInput($text, 80, 25, 80, 21) Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18) Global $CheckBox1 = GUICtrlCreateCheckbox("1111111", 8, 48, 110, 17) Global $CheckBox2 = GUICtrlCreateCheckbox("2222222", 8, 72, 110, 17) Global $CheckBox3 = GUICtrlCreateCheckbox("333333333", 8, 96, 110, 17) Global $CheckBox4 = GUICtrlCreateCheckbox("444444444", 8, 120, 110, 17) Global $CheckBox5 = GUICtrlCreateCheckbox("55555555", 8, 144, 110, 17) Global $CheckBox6 = GUICtrlCreateCheckbox("666666666", 8, 168, 110, 17) Global $CheckBox7 = GUICtrlCreateCheckbox("77777777", 8, 192, 150, 17) Global $CheckBox8 = GUICtrlCreateCheckbox("888888888", 8, 216, 150, 17) Global $CheckBox9 = GUICtrlCreateCheckbox("99999999", 8, 240, 110, 17) Global $CheckBox10 = GUICtrlCreateCheckbox("45646", 8, 264, 110, 17) Global $CheckBox11 = GUICtrlCreateCheckbox("4345634", 8, 288, 97, 17) Global $CheckBox12 = GUICtrlCreateCheckbox("4563456", 8, 312, 97, 17) Global $CheckBox13 = GUICtrlCreateCheckbox("456456", 8, 336, 97, 17) GUICtrlCreateTabItem("TAB 2") Global $InputCaseID2 = GUICtrlCreateInput("", 80, 25, 80, 21) Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18) Global $CheckBox14 = GUICtrlCreateCheckbox("AAAAAAA", 8, 48, 110, 17) Global $CheckBox15 = GUICtrlCreateCheckbox("PPPPPPPPP", 8, 72, 110, 17) Global $CheckBox16 = GUICtrlCreateCheckbox("BBBBBBBB", 8, 96, 110, 17) Global $CheckBox17 = GUICtrlCreateCheckbox("CCCCCCCCCCCCC", 8, 120, 110, 17) Global $CheckBox18 = GUICtrlCreateCheckbox("DDDDDDDDDDDDD", 8, 144, 110, 17) Global $CheckBox19 = GUICtrlCreateCheckbox("EEEEEEEEEE", 8, 168, 110, 17) Global $CheckBox20 = GUICtrlCreateCheckbox("FFFFFFFFFFF", 8, 192, 150, 17) Global $CheckBox21 = GUICtrlCreateCheckbox("GGGGGGGGGG", 8, 216, 150, 17) Global $CheckBox22 = GUICtrlCreateCheckbox("HHHHHHHHH", 8, 240, 110, 17) Global $CheckBox23 = GUICtrlCreateCheckbox("IIIIIIIII", 8, 264, 110, 17) Global $CheckBox24 = GUICtrlCreateCheckbox("JJJJJJJ", 8, 288, 97, 17) Global $CheckBox25 = GUICtrlCreateCheckbox("KKKKKKKKKKK", 8, 312, 97, 17) Global $CheckBox26 = GUICtrlCreateCheckbox("LLLLLLLLL", 8, 336, 97, 17) GUICtrlCreateTabItem("") Global $CheckBoxAlwaysOnTop = GUICtrlCreateCheckbox("Always on Top", 8, 380, 97, 17) Global $btnReset = GUICtrlCreateButton("RESET", 104, 365, 75, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $CheckBoxAlwaysOnTop _SetAlwaysOnTop() Case $btnReset For $i = 7 To 19 Step 1 ;Remove checked CheckBoxes GUICtrlSetState($CheckBox&$i, $GUI_UNCHECKED) Next For $i = 23 To 35 Step 1 GUICtrlSetState($CheckBox&$i, $GUI_UNCHECKED) Next GUICtrlSetData($InputCaseID1, "") GUICtrlSetData($InputCaseID2, "") EndSwitch WEnd Func _SetAlwaysOnTop() If GUICtrlRead($CheckBoxAlwaysOnTop) = $GUI_CHECKED Then WinSetOnTop($Form, "", 1) ;On top Else WinSetOnTop($Form, "", 0) ;Not on top EndIf EndFunc ;==>_SetAlwaysOnTop My question is:
      Why this  For loop for GUICtrlSetState($CheckBox&$i, $GUI_UNCHECKED) does not work properly
      I have $CheckBox1, $CheckBox2.......till $CheckBox26 and with For $i = 1 To 26 it does not work. It only unchecks few of them, but not all.
      Later I have discovered that For $i = 7 To 19 removes  $CheckBox1 to  $CheckBox13 and For $i = 23 To 35 removes  $CheckBox14 to  $CheckBox26
      Any idea why?
    • lavascript
      By lavascript
      I have a Word document containing a 9-column table where row 1 is the column headers. My goal is to read the table into a 2d array, remove some rows, update some fields, and add a few rows to the end. The resulting array will likely be a different length. Next, I want to write the data back into the table. If it's easier, I can write the data to a new document from a template containing the same table header with a blank 2nd row.
      Here's my early attempt:
      Local $oWord = _Word_Create() Local $oDoc = _Word_DocOpen($oWord, $sFile) Local $aData = _Word_DocTableRead($oDoc, 1) $aData[3][5] = "Something else" Local $oRange = _Word_DocRangeSet($oDoc, 0) $oRange = _Word_DocRangeSet($oDoc, $oRange, $wdCell, 9) _Word_DocTableWrite($oRange,$aData) This, unfortunately, writes the entire array into the first cell of row 2. What am I doing wrong?
       
    • OneSolution
      By OneSolution
      Hi guys! I have these checkbox that I'm trying to click on. They have the same inner-text string but a different ID. Sometime there can be as many as 4 checkbox
      with the same string but the ID is always different. I tried a few methods down below but I'm unable to make any real results. Any suggestions or solutions I would
      appreciate it very much.
      <ul><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-2"><!-- react-text: 675 -->Morning<!-- /react-text --><!-- react-text: 676 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 678 -->OTHER<!-- /react-text --><!-- react-text: 679 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 681 -->8:30 AM<!-- /react-text --><!-- react-text: 682 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 684 -->10:30 AM<!-- /react-text --><!-- react-text: 685 -->&nbsp;<!-- /react-text -- ></div><div class="cx-item-contents col-md-1"><!-- react-text: 687 -->SRV<!-- /react-text --><!-- react-text: 688 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox1" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox1"></label></div></div></div></li><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-1"><!-- react-text: 698 -- >Morning<!-- /react-text --><!-- react-text: 699 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 701 -->OTHER<!-- /react- text --><!-- react-text: 702 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 704 -->8:30 AM<!-- /react-text --><!-- react-text: 705 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 707 -->2:30 PM<!-- /react-text --><!-- react-text: 708 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 710 -->SRV<!-- /react-text --><!-- react-text: 711 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox2" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox2"></label></div></div></div></li></ul> I tried the _IETagNameGetCollection() but it only check the box but doesn't fire the event! And I'm unable to submit that without a click action.
      Func _Box1() $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id == "cx_checkbox1" Then $oInput.checked = true Next Sleep(10) ToolTip('box1') EndFunc ;==>_Box1 I also tried click by text.The boxes do get check by a click but the problem with that is it will select every box that has the same string. I'm allowed only to check 1 box selection at a time per day for the submit button to work.  Any preference to select only the second box and bypass the other?
      Func _Morning() For $a In _IETagNameGetCollection($oIE, "div") If StringInStr(_IEPropertyGet($a, "innerText"), "Morning") Then _IEAction($a, "click") EndIf Next Sleep(10) ToolTip('Morning selected') EndFunc ;==>Morning The last method I tried was _IEGetObjById(). It doesn't click or respond to the checkbox.
      Func _Click1() $oChk = _IEGetObjById($oIE, "cx_checkbox1") _IEAction($oChk, 'click') Sleep(20) ToolTip('box1') EndFunc ;==>_Click1  
    • Subz
      By Subz
      Backstory:
      Our Microsoft Office Templates shared folder was changed from a DFS share to an Isilon share. example:
      Old Server: \\Domain.com\Office\Templates
      New Server: \\Templates.domain.com\Office\Templates
      The team making the changes overlooked that several hundred thousand documents, had been attached to the old template documents.  So when you open a document which has been attached, it will take a couple of minutes to open, while it tries to locate the old server path.  I've been asked to come in and fix it, so after several hours found that the data is being held in document.zip\word\_rels\settings.xml.rels, I now need to replace the old server path with the new server path.  I didn't want to use dom as that would take too long and found a tool wtc https://github.com/NeosIT/wtc which  works perfectly, takes about 8 minutes to scan a single directory with 4000 documents and fix them.  The problem is the documents are all held on sharepoint and they want to retain the file timestamp, which is easy enough, but they also don't want to keep the "Modified By" apparently they don't like seeing all the documents appearing as "Modified by: Subz"  Anyone know of way to retain the "Modified By" info,
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am working with Word UDF ( thanks @water! ), and, especially, with the function _Word_DocFindReplace().
      The replace does work everywhere in the document, but, it does not work in Headers or Footers.
      Am I missing something or am I forced to use the code below?
      I have already looked in the Help file ( about _Word_DocFindReplace() ), but there are no mentions about replace text in Headers/Footers.
      Sub FindAndReplaceFirstStoryOfEachType() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges With rngStory.Find .Text = "find text" .Replacement.Text = "I'm found .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next rngStory End Sub Thanks everyone in advance


      Best Regards.
×