Jump to content

MS Word RTF problem


Recommended Posts

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 by saywell
Link to comment
Share on other sites

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 - 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 (NEW 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

 

Link to comment
Share on other sites

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 - 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 (NEW 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

 

Link to comment
Share on other sites

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 - 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 (NEW 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

 

Link to comment
Share on other sites

  • 3 years later...

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

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 - 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 (NEW 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

 

Link to comment
Share on other sites

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

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 - 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 (NEW 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

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...