myspacee Posted March 11, 2009 Share Posted March 11, 2009 (edited) Hello, i've created .doc with barcode. I want to replace text (is in readable form inside .doc) without touch file structure to avoid destroy it. Manually things work, so I need : - to open file - replace text : - save it in another .doc write this (bad) script: $file = FileOpen("Copia di doc2.doc", 1) $file_read = FileRead($file) $changed = StringReplace($file_read, "IT0900071","IT09XXX71") $fileb = FileOpen("test.doc", 10) FileWriteLine($fileb, $changed) FileClose($file) but doesn't works... Can anyone correct me ? thank you, m. Edited March 11, 2009 by myspacee Link to comment Share on other sites More sharing options...
James Posted March 11, 2009 Share Posted March 11, 2009 DOC files are encrypted. Look at the Word.au3 UDF. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Authenticity Posted March 11, 2009 Share Posted March 11, 2009 The first call to FileOpen() was called with the last parameter set to 1 (write mode) so you can't read it. Just read the entire file without bothering to open a handle associated with it, like: $sSource = FileRead("FileName.doc").Another thing that I never have had experience before is opening a file with "Create directory structure if it doesn't exist (8) option. It seems to me much simpler to open it just with the last parameter set to 2. Link to comment Share on other sites More sharing options...
James Posted March 11, 2009 Share Posted March 11, 2009 This should work: #include <Word.au3> $File "Copia di doc2.doc" $oWordApp = _WordCreate ("") $oWord = _WordDocOpen($oWordApp, $File) _WordDocFindReplace($oWordApp, "IT0900071","IT09XXX71") _WordQuit($oWordApp) Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
myspacee Posted March 12, 2009 Author Share Posted March 12, 2009 read now replies, thank you all, now testing code m. Link to comment Share on other sites More sharing options...
myspacee Posted March 12, 2009 Author Share Posted March 12, 2009 (edited) test failed on my word >"C:\Programmi\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\a.user\Desktop\Nuovo AutoIt v3 Script.au3" C:\Programmi\AutoIt3\Include\Word.au3 (459) : ==> The requested action with this object has failed.: $o_doc = $o_object.Documents.Open ($s_FilePath, $f_ConfirmConversions, $f_ReadOnly, $f_AddToRecentFiles, $s_PasswordDocument, "", $f_Revert, $s_WritePasswordDocument, "", $i_Format) $o_doc = $o_object.Documents.Open ($s_FilePath, $f_ConfirmConversions, $f_ReadOnly, $f_AddToRecentFiles, $s_PasswordDocument, "", $f_Revert, $s_WritePasswordDocument, "", $i_Format)^ ERROR >Exit code: 1 Time: 1.093 my file has not password, and is in office 2003 format. anyone can help ? m. Edited March 12, 2009 by myspacee Link to comment Share on other sites More sharing options...
James Posted March 12, 2009 Share Posted March 12, 2009 Well I gave you a start, why don't you read the help file? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
myspacee Posted March 12, 2009 Author Share Posted March 12, 2009 James thank you for all, taken this from help #include <Word.au3> $oWordApp = _WordCreate (@ScriptDir & "\Copia di doc2.doc") $oDoc = _WordDocGetCollection($oWordApp, 0) $oFind = _WordDocFindReplace($oDoc, "IT0900071", "IT0900073") If $oFind Then MsgBox(0, "FindReplace", "Found and replaced.") Else MsgBox(0, "FindReplace", "Not Found with error : " & @Error) EndIf _WordQuit ($oWordApp, 0) return error 7 ($_WordStatus_NoMatch) = No Match) How this works ? is capable to read inside a text box ? thank you again for your time, m. 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