Jump to content

Recommended Posts

Posted

Hi Guys

I have hundreds of word templates and need to loop through them checking each one for the existence of checkboxes. I have googled but not found anything useful.

Is this possible? Any tips on how I can achieve it?

Cheers

Posted

You could either use the Word UDF that comes with AutoIt or my of the Word UDF which better handles processing of many files.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Hi water

Thanks for that. Very useful. From this I can build a list of docs and open them. I see there's also a Find/Replace (find being important in my case). But how would I 'find' a checkbox?

Thanks

Posted

What do you want to do with the found checkboxes?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Simply know that they are present. If they exist I will write the name of the file to a text file or something. I have to remove these which I will get someone to do manually - just hoping to narrow it down to save them hunting through every template :

Posted

Which version of Word do you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Example to scan a Word document for checkboxes using my It would be easy to delete all checkboxes and save the files with a new name.

#include <WordEx.au3>

Global $sDocument = "Test_Checkbox.docx" ; <=== Change path/name

; WdFieldType Enumeration. Specifies a Microsoft Office Word field.
; See: http://msdn.microsoft.com/en-us/library/bb213727%28v=office.12%29.aspx
Global Const $wdFieldFormCheckBox = 71 ; FormCheckBox field

; WdContentControlType Enumeration. Indicates the type of content control.
; See: http://msdn.microsoft.com/en-us/library/ff197873%28v=office.14%29.aspx
Global Const $wdContentControlCheckbox = 8 ; Specifies a checkbox content control

; Create application object
Global $oWord = _Word_Create()
If @error <> 0 Then Exit MsgBox(16, "Word Example", "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open document
Global $oDoc = _Word_DocOpen($oWord, $sDocument)
If @error <> 0 Then Exit MsgBox(16, "Word Example", "Error opening 'Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

For $oContentControl In $oDoc.ContentControls
    If $oContentControl.Type = $wdContentControlCheckbox Then
         MsgBox(64, "Word Example", "Checkbox found!")
        ; $oContentControl.Delete(True) <== Delete the Control
    EndIf
Next

_Word_DocClose($oDoc)
_Word_Quit($oWord)
Exit
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Thanks water.

I tried this but I can't see to get it to identify checkboxes within the file. I am reading .dot template files if that's a problem. However, it opens OK.

Changed it slightly just to read a file first :

#include <File.au3>
#include <../_WordEx 1.3/WordEx.au3>

Global $sDocument
; = "C:\AutoIT\Checkboxes\checkbox.dot" ; <=== Change path/name

; WdFieldType Enumeration. Specifies a Microsoft Office Word field.
; See: http://msdn.microsoft.com/en-us/library/bb213727%28v=office.12%29.aspx
Global $wdFieldFormCheckBox = 71 ; FormCheckBox field

; WdContentControlType Enumeration. Indicates the type of content control.
; See: http://msdn.microsoft.com/en-us/library/ff197873%28v=office.14%29.aspx
Global $wdContentControlCheckbox = 8 ; Specifies a checkbox content control

$file = @SCRIPTDIR & "\smalltemplatelist.txt"
FileOpen($file, 0);

For $i = 1 to _FileCountLines($file)
$line = FileReadLine($file, $i)
$sDocument = $line
Check()
Next
FileClose($file)

Func Check()

; Create application object
Global $oWord = _Word_Create()
If @error <> 0 Then Exit MsgBox(16, "Word Example", "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open document
Global $oDoc = _Word_DocOpen($oWord, $sDocument)
If @error <> 0 Then Exit MsgBox(16, "Word Example", "Error opening 'Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

For $oContentControl In $oDoc.ContentControls
If $oContentControl.Type = $wdContentControlCheckbox Then
         MsgBox(64, "Word Example", "Checkbox found!")
     ; $oContentControl.Delete(True) <== Delete the Control
EndIf
Next

_Word_DocClose($oDoc)
_Word_Quit($oWord)
EndFunc
Edited by kiffab
Posted (edited)

Google: Word VBA CheckBox

first result:

The following example selects the check box form field named "Check1" in the active document.

Activedocument.FormFields("Check1").CheckBox.Value = True

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted

Unfortunately this is only true for Word 2007. My example above is for Word 2010. See the difference?

In your example you need to know the name of the Checkbox. But the OP needs a way to access the collection of all controls.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

No, that's a way to single out one object of a col...you can get the full collection by removing that, and then loop through:

$oObjCol = $oWord.Activedocument.FormFields
 For $oObj In $oObjCol
  ConsoleWrite($oObj.name &  @CRLF)
 Next
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted

I tried this but I can't see to get it to identify checkboxes within the file. I am reading .dot template files if that's a problem. However, it opens OK.

Could you please post one of your .dot files?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Could you please post one of your .dot files?

I can't upload these as they contain data, built in fields etc.However, when I add the code posted by jdelaney it is returning the name of the checkbox in the console.

The template is a 'word 97-2003' template (probably 2003) but my PC is running word 2010 if that helps at all.

Posted

I tried to create a .dot file for Word 97-2003 with Word 2010 but when saving it drops all checkboxes.

Can you create a reproducer .dot file with a checkbox and without company related info with an old version of Word?

Or if you like you can send me a .dot file by private mail of this forum. I promise to delete the file as soon as the problem is solved!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...