crystalburner Posted August 9, 2006 Share Posted August 9, 2006 doesnt seem to work on word docs i see it requires a control ID word doesnt seem to return one to the autoitwindow info tool Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 9, 2006 Moderators Share Posted August 9, 2006 Is there a question here? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
crystalburner Posted August 9, 2006 Author Share Posted August 9, 2006 Is there a question here?Scary I know but one of you will be the lucky guy to be awarded the 5 * scripter of the month award. So who is it going to be then?Who will be first, who is the best? Who is the mac daddy of AutoIT?Ready, set..... GO FOR YOUR KEYBOARDS! Link to comment Share on other sites More sharing options...
crystalburner Posted August 9, 2006 Author Share Posted August 9, 2006 Scary I know but one of you will be the lucky guy to be awarded the 5 * scripter of the month award. So who is it going to be then?Who will be first, who is the best? Who is the mac daddy of AutoIT?Ready, set..... GO FOR YOUR KEYBOARDS!LOLOk well to put it simplyi need to change the text of a document without using SEND commandsany ideas?(its word 2003) Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 9, 2006 Moderators Share Posted August 9, 2006 You need to ask a question (preferably with as much detail as possible) before we can help you. Link to comment Share on other sites More sharing options...
crystalburner Posted August 9, 2006 Author Share Posted August 9, 2006 You need to ask a question (preferably with as much detail as possible) before we can help you. I have a word document that contains dummy pieces of text like this [name] [address1] [address2] Dear [name] I have a script that contains variables like $name = "nick christou" $address1="6 south island place" $address2="London" I want to modify the word document to replace these dummy pieces of text with my strings kind of like ControlSetText ( "mydoc.doc - Microsoft Word", "[name]", "", $name , -1 ) except this doesnt work, i think because word returns no control IDs hence i have left it blank and also tried edit1 and -1 Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 9, 2006 Moderators Share Posted August 9, 2006 (edited) When you say "dummy pieces", are you refering to fields? If so then you will need to use com objects to update the fields with your variables. Otherwise if they are just text, then you can still use com but with a find method. Edit: spelling Edited August 9, 2006 by big_daddy Link to comment Share on other sites More sharing options...
crystalburner Posted August 9, 2006 Author Share Posted August 9, 2006 When you say "dummy pieces", are you refering to fields? If so then you will need to use com objects to update the fields with your variables. Otherwise if they are just text, then you can still use com but with a find method.Edit: spellingi cant use COM cos smoke doesnt know how to do that Link to comment Share on other sites More sharing options...
crystalburner Posted August 9, 2006 Author Share Posted August 9, 2006 i cant use COM cos smoke doesnt know how to do thatand to be honest neither do Isurely this is a fairly common request has nobody had to do this be4? Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 9, 2006 Moderators Share Posted August 9, 2006 i cant use COM cos smoke doesnt know how to do thatDo you have some kind of contract with SmOke_N that I'm not aware of? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 9, 2006 Moderators Share Posted August 9, 2006 Ha!!, how the hell did I get brought into this Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
crystalburner Posted August 9, 2006 Author Share Posted August 9, 2006 Ha!!, how the hell did I get brought into this you're my mate smokey Link to comment Share on other sites More sharing options...
crystalburner Posted August 9, 2006 Author Share Posted August 9, 2006 you're my mate smokeyThere are lots of contacts with SmOke you aren't aware of.Ask his wife Link to comment Share on other sites More sharing options...
crystalburner Posted August 9, 2006 Author Share Posted August 9, 2006 There are lots of contacts with SmOke you aren't aware of.Ask his wife im offand dissapointed cos i've seen some impressive stuff here but nobody seems to be able to just change some text in a word docim amazedi think there will be a workaround, open the file in raw mode and replace things (ouch) use another prog to do the replace, @SW_HIDE word and use SEND keysdunnowill let you know anyhow what worked Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 9, 2006 Moderators Share Posted August 9, 2006 (edited) So do you want help on this or not? If you do, then you need to answer my question above. Edit: Just read your previous post. Do you seriously expect an answer to your "question" with what you have provided so far? Edited August 10, 2006 by big_daddy Link to comment Share on other sites More sharing options...
crystalburner Posted August 10, 2006 Author Share Posted August 10, 2006 So do you want help on this or not? If you do, then you need to answer my question above. Edit: Just read your previous post. Do you seriously expect an answer to your "question" with what you have provided so far? What do you need to know? Open word type in [blank] save it now change that [blank] piece of text u just typed automatically i really dont understand what else i need to tell you i want to do an automatic find and replace on a word doc im shocked nobody has done this before Link to comment Share on other sites More sharing options...
crystalburner Posted August 10, 2006 Author Share Posted August 10, 2006 So do you want help on this or not? If you do, then you need to answer my question above. Edit: Just read your previous post. Do you seriously expect an answer to your "question" with what you have provided so far? What do you need to know? Open word type in [blank] save it now change that [blank] piece of text u just typed automatically i really dont understand what else i need to tell you i want to do an automatic find and replace on a word doc im shocked nobody has done this before Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 10, 2006 Moderators Share Posted August 10, 2006 This does what you are wanting.Requires:Word.au3 - check my signatureexpandcollapse popup#include <Word.au3> ; Register the default Word.au3 COM Error Handler _WordErrorHandlerRegister () ; Specify a file path for later use $sFilePath = @ScriptDir & "\Test.doc" ; Try to attach to existing word window with the specified ; file, if one does not exist it will be created $oWordApp = _WordCreate ($sFilePath) Sleep(2000) ; Get reference to the active document $oDoc = $oWordApp.ActiveDocument ; Get a range of the entire document $oRng = $oDoc.Range ; Set the text for the entire document $oRng.Text = "[name]" & @CRLF & @CRLF & _ "[address1]" & @CRLF & @CRLF & _ "[address2]" & @CRLF & @CRLF & _ "Dear [name]" Sleep(2000) ; Close document, saving changes, with original document format _WordDocumentClose($oDoc, -1, 1) Sleep(2000) ; Open the document, returning the active document object $oDoc = _WordDocumentOpen($oWordApp, $sFilePath) Sleep(1000) ; Find and replace text within the document _FindReplace($oDoc, "[name]", "Joe Shmoe") Sleep(1000) ; Find and replace text within the document _FindReplace($oDoc, "[address1]", "12345 Broadway Ave.") Sleep(1000) ; Find and replace text within the document _FindReplace($oDoc, "[address2]", "Los Angeles, CA 54321") Func _FindReplace($o_object, $s_search, $s_replace) If Not IsObj($o_object) Then SetError(1) Return 0 EndIf $o_Rng = $o_object.Range $o_Find = $o_Rng.Find $o_Find.Execute ( _ $s_search, _ ; FindText False, _ ; MatchCase True, _ ; MatchWholeWord False, _ ; MatchWildcards False, _ ; MatchSoundsLike False, _ ; MatchAllWordForms True, _ ; Forward 1, _ ; wdFindStop = 0, wdFindContinue = 1, wdFindAsk = 2 False, _ ; Format $s_replace, _ ; ReplaceWith 2) ; wdReplaceNone = 0, wdReplaceOne = 1, wdReplaceAll = 2 EndFunc ;==>_FindReplace Link to comment Share on other sites More sharing options...
crystalburner Posted August 10, 2006 Author Share Posted August 10, 2006 BD i will give this a go sorry i didnt reply earlier it was 1am had to sleeeep! This does what you are wanting. Requires: Word.au3 - check my signature expandcollapse popup#include <Word.au3> ; Register the default Word.au3 COM Error Handler _WordErrorHandlerRegister () ; Specify a file path for later use $sFilePath = @ScriptDir & "\Test.doc" ; Try to attach to existing word window with the specified ; file, if one does not exist it will be created $oWordApp = _WordCreate ($sFilePath) Sleep(2000) ; Get reference to the active document $oDoc = $oWordApp.ActiveDocument ; Get a range of the entire document $oRng = $oDoc.Range ; Set the text for the entire document $oRng.Text = "[name]" & @CRLF & @CRLF & _ "[address1]" & @CRLF & @CRLF & _ "[address2]" & @CRLF & @CRLF & _ "Dear [name]" Sleep(2000) ; Close document, saving changes, with original document format _WordDocumentClose($oDoc, -1, 1) Sleep(2000) ; Open the document, returning the active document object $oDoc = _WordDocumentOpen($oWordApp, $sFilePath) Sleep(1000) ; Find and replace text within the document _FindReplace($oDoc, "[name]", "Joe Shmoe") Sleep(1000) ; Find and replace text within the document _FindReplace($oDoc, "[address1]", "12345 Broadway Ave.") Sleep(1000) ; Find and replace text within the document _FindReplace($oDoc, "[address2]", "Los Angeles, CA 54321") Func _FindReplace($o_object, $s_search, $s_replace) If Not IsObj($o_object) Then SetError(1) Return 0 EndIf $o_Rng = $o_object.Range $o_Find = $o_Rng.Find $o_Find.Execute ( _ $s_search, _ ; FindText False, _ ; MatchCase True, _ ; MatchWholeWord False, _ ; MatchWildcards False, _ ; MatchSoundsLike False, _ ; MatchAllWordForms True, _ ; Forward 1, _ ; wdFindStop = 0, wdFindContinue = 1, wdFindAsk = 2 False, _ ; Format $s_replace, _ ; ReplaceWith 2) ; wdReplaceNone = 0, wdReplaceOne = 1, wdReplaceAll = 2 EndFunc ;==>_FindReplace Link to comment Share on other sites More sharing options...
crystalburner Posted August 10, 2006 Author Share Posted August 10, 2006 BD i will give this a go sorry i didnt reply earlier it was 1am had to sleeeep!yepTHANKSBIG D! 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