KenNichols Posted May 20, 2009 Posted May 20, 2009 (edited) I can change the text of a Bookmark with this $CompletedBy = "Ken Nichols" $oWordApp.Activedocument.Bookmarks("preparedby").Range.Text = $CompletedBy How would I change the value of a CheckBox? I found the following VBA code on the web, but it will not work for me. $oWordApp.Activedocument.FormFields("checkbox1").CheckBox.Value = True I think I need to do a Collection of the FormFields but I have no idea on how to do that. I really hate to keep asking. But I really need help with this. Edited May 21, 2009 by KenNichols [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
LurchMan Posted May 21, 2009 Posted May 21, 2009 look up the word UDF in the help file Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
Moderators big_daddy Posted May 21, 2009 Moderators Posted May 21, 2009 (edited) The code you posted is formatted correctly. The part I highlighted either needs to be the index number or the bookmark name name associated with the check box.$oWordApp.Activedocument.FormFields("checkbox1").CheckBox.Value = TrueCheckBox Object Edited May 21, 2009 by big_daddy Added reference link
KenNichols Posted May 21, 2009 Author Posted May 21, 2009 (edited) The code you posted is formatted correctly. The part I highlighted either needs to be the index number or the bookmark name name associated with the check box.CheckBox ObjectHow do I find the index number?I created a bookmark called "test" on the checkbox and got thisC:\Documents and Settings\Technician\Desktop\Word Test\CheckBox.au3 (4) : ==> The requested action with this object has failed.:$oWordApp.Activedocument.FormFields("test").CheckBox.Value = True$oWordApp.Activedocument.FormFields("test")^ ERRORI also tried$oWordApp.Activedocument.Bookmarks("test").Range.Text = "This is a test!!!"and it replaces the checkbox with "This is a test!!!" Edited May 21, 2009 by KenNichols [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
Moderators big_daddy Posted May 21, 2009 Moderators Posted May 21, 2009 See what you get with this. The form field # or name is what you need to use. #include <Word.au3> Const $wdFieldFormCheckBox = 71 Global $iIndex = 1 Global $sFilePath = "C:\temp\test.docx" _WordErrorHandlerRegister() Global $oWordApp = _WordCreate($sFilePath, 1) Global $oDoc = _WordDocGetCollection($oWordApp, 0) Global $oFormFields = $oDoc.FormFields() If IsObj($oFormFields) Then ConsoleWrite("Total Form Fields: " & $oFormFields.Count & @CR) ConsoleWrite("==================================================" & @CR) Else ConsoleWrite("There are no form fields in this document." & @CR) Exit EndIf For $oFormField In $oFormFields ConsoleWrite("Form Field #" & $iIndex & @CR) ConsoleWrite("Name: " & $oFormField.Name & @CR) ConsoleWrite("Type: " & $oFormField.Type & @CR) ; http://msdn.microsoft.com/en-us/library/bb213727.aspx If $oFormField.Type = $wdFieldFormCheckBox Then ConsoleWrite("CheckBox Value: " & $oFormField.CheckBox.Value & @CR) EndIf ConsoleWrite("==================================================" & @CR) $iIndex += 1 Next
KenNichols Posted May 21, 2009 Author Posted May 21, 2009 On my test doc I get Total Form Fields: 0 on the other 1 I get Total Form Fields: 47 ================================================== Form Field #1 Name: Type: 70 ================================================== Form Field #2 Name: Type: 70 ================================================== Form Field #3 Name: FormDate Type: 70 ================================================== Form Field #4 Name: preparedby Type: 70 ================================================== Form Field #5 Name: companyname Type: 70 etc etc.................... [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
Moderators big_daddy Posted May 21, 2009 Moderators Posted May 21, 2009 See here for the WdFieldType Enums. You are looking for type 71.
KenNichols Posted May 21, 2009 Author Posted May 21, 2009 See here for the WdFieldType Enums. You are looking for type 71.There is no type 71's! I don't understand why there like 20 checkboxs in the file! [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
Moderators big_daddy Posted May 21, 2009 Moderators Posted May 21, 2009 There is no type 71's! I don't understand why there like 20 checkboxs in the file!Can you send me the document via PM?
KenNichols Posted May 21, 2009 Author Posted May 21, 2009 Can you send me the document via PM?I will try [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
Moderators big_daddy Posted May 22, 2009 Moderators Posted May 22, 2009 This was a tricky one. expandcollapse popup#include <Word.au3> Const $wdFieldFormCheckBox = 71 Const $wdFieldOCX = 87 Const $wdFieldFormTextInput = 70 Const $wdHalfCheck = -1 Const $wdUnCheck = 0 Const $wdFullCheck = 1 Global $iIndex = 1 Global $sFilePath = "C:\temp\test.docx" _WordErrorHandlerRegister() Global $oWordApp = _WordCreate($sFilePath, 1) Global $oDoc = _WordDocGetCollection($oWordApp, 0) Global $oFields = $oDoc.Fields If IsObj($oFields) Then ConsoleWrite("Total Fields: " & $oFields.Count & @CR) ConsoleWrite("==================================================" & @CR) Else ConsoleWrite("There are no fields in this document." & @CR) Exit EndIf For $oField In $oFields If $oField.Type = $wdFieldOCX Then With $oField ConsoleWrite("Index #" & .Index & @CR) ConsoleWrite("Type: " & .Type & @CR) ; http://msdn.microsoft.com/en-us/library/bb213727.aspx $oCheckBox = .InlineShape.OLEFormat EndWith With $oCheckBox ConsoleWrite("ClassType: " & .ClassType & @CR) If .ClassType = "Forms.CheckBox.1" Then ConsoleWrite("Old Value: " & .Object.Value & @CR) .Object.Value = $wdFullCheck ConsoleWrite("New Value: " & .Object.Value & @CR) EndIf EndWith ConsoleWrite("==================================================" & @CR) EndIf $iIndex += 1 Next
KenNichols Posted May 22, 2009 Author Posted May 22, 2009 Thank You! That is awsome! [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
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