saywell Posted June 5, 2012 Share Posted June 5, 2012 (edited) I've been creating word docs using AutoIT, with no problems, thinking they were rtfs as I'd created them with the .rtf suffix. However, I've discovered [see thread passim if you can be bothered!] that in fact they are just 'do files with .rtf file extension. IE in 'doc' format rather than 'rtf format' I now need to use proper RTFs which I can now do [previously I'd not used the $i_Format = 6 in the save as command]. Howvever, I've hit a snag in the search/replace functionality. What I need to do is a search and replace on a group of letters [from the template] and replace it with an address block - ie several lines of address. When I do this, the line breaks don't carry over into the final document. I've tried using @CR, @CRLF, @LF and @CR & &LF but none works. Can anyone help Please? Here is a simulator - I tried to upload the template, but apparently "You aren't permitted to upload this kind of file". It's just a blank word document with the word 'This' about half-way down the page, saved in .dot format. ; ******************************************************* ; RTF Test - [delete previous example when restarting] ; Create a word window, ; open a document, find "This", ; replace all occurrences with "THIS", save in RTF format. ; open to view result ; ******************************************************* ; #include <Word.au3> Opt("WinTitleMatchMode", 2) FileDelete (@ScriptDir & "Test.rtf") ; to remove the previous attempt $oWordApp = _WordCreate ("") WinClose ("Document 1") ; close extra window spawned when opening Word $Template = @ScriptDir & "RTFtest_letter.dot" $oOpenTemplate = _WordDocAdd ($oWordApp,0,$Template) $oDoc = _WordDocGetCollection($oWordApp, 0) $sReplace = "Line 1" &@CR&"Line2" $oFind = _WordDocFindReplace($oOpenTemplate, "This", $sReplace) If $oFind Then MsgBox(0, "FindReplace", "Found and replaced.",1) Else MsgBox(0, "FindReplace", "Not Found") EndIf $Template = @ScriptDir & "referral_letter.dot" _WordDocSaveAs ($oOpenTemplate,@ScriptDir & "Test.rtf",6) _WordQuit ($oWordApp, 0) ShellExecute (@ScriptDir & "Test.rtf") ; to see the final result Thanks, William Edited June 5, 2012 by saywell Link to comment Share on other sites More sharing options...
water Posted June 5, 2012 Share Posted June 5, 2012 According to this site you need to set "^p" for a hard return (paragraph mark) or "^|" for a soft return (manual line breaks) in your replacement text. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
saywell Posted June 5, 2012 Author Share Posted June 5, 2012 Thanks, Water. I tried $sReplace = "Line 1" &"^|"&"Line2" In my test script, but it just threw up an error in the [included] <Word.au3> that crashed the test script. William Link to comment Share on other sites More sharing options...
water Posted June 5, 2012 Share Posted June 5, 2012 Just tried it myself. "^|" crashes but "^p" works just fine. Give it a try. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
saywell Posted June 5, 2012 Author Share Posted June 5, 2012 Indeed it does - you're a star!! Many thanks. William Link to comment Share on other sites More sharing options...
water Posted June 5, 2012 Share Posted June 5, 2012 Don't exaggerate I'm just good with Google. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Thomymaster Posted June 29, 2015 Share Posted June 29, 2015 Just tried it myself. "^|" crashes but "^p" works just fine. Give it a try.Hi I am using AutoIT 3.3.12.0 and after i read a MS Word document via _Word_DocTableRead() and tried to detect soft-returns via "^|" i found that the detection doesn't work (i want to replace all soft-returns by hard-returns).Is there any hint for me? Best,Thomas Link to comment Share on other sites More sharing options...
water Posted June 29, 2015 Share Posted June 29, 2015 Can you please post your code?I'm not sure you can determine if it is a hard or soft break after _Word_DocTableRead. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Thomymaster Posted July 7, 2015 Share Posted July 7, 2015 Hi The code is $i=2 While $i<=$iTableEntries-1 If StringInStr($sLine,"^|") Then ; this approach to soft-return detection doesn't detect 29.06.2015 $sLine=StringReplace($sLine,"^|",@CR) EndIf $i+=1 Wend Link to comment Share on other sites More sharing options...
water Posted July 7, 2015 Share Posted July 7, 2015 Will need to test. But as I'm on vacation right now it will take some time. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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