G
GuyVerville
I have some scripts to prepare a Word document for a migration to Dreamweaver. I prefer coding a clean text instead of relying of the way Word saves HTML files.
I would like to work on a particular selection of text (replacing some text with another text). Here is the script:
=======================
tell application "Microsoft Word"
set myRange to text object of selection
my remplacerLI(myRange)
end tell
on remplacerLI(myRange)
my Remplacer("<p>", "<li>", myRange)
my Remplacer("</p>", "</li>", myRange)
end remplacerLI
on Remplacer(findText, replaceText, myRange)
tell application "Microsoft Word"
set theRange to myRange
my ReplaceInRange(findText, replaceText, theRange)
end tell
end Remplacer
on ReplaceInRange(findText, replaceText, theRange)
tell application "Microsoft Word"
set findObject to find object of theRange
tell findObject
set format to false
set content to findText
set content of its replacement to replaceText
set wrap to find stop
set match case to true
end tell
execute find findObject replace replace all
end tell
end ReplaceInRange
========================
After the first pass (the first call of remplacerLI function), the selection vanishes. I thought setting a range of text before calling it might resolve the problem, but this doesn't seem to work and the second call of the function remplacerLI applies to all the active document. I'm a little lost.
I would like to work on a particular selection of text (replacing some text with another text). Here is the script:
=======================
tell application "Microsoft Word"
set myRange to text object of selection
my remplacerLI(myRange)
end tell
on remplacerLI(myRange)
my Remplacer("<p>", "<li>", myRange)
my Remplacer("</p>", "</li>", myRange)
end remplacerLI
on Remplacer(findText, replaceText, myRange)
tell application "Microsoft Word"
set theRange to myRange
my ReplaceInRange(findText, replaceText, theRange)
end tell
end Remplacer
on ReplaceInRange(findText, replaceText, theRange)
tell application "Microsoft Word"
set findObject to find object of theRange
tell findObject
set format to false
set content to findText
set content of its replacement to replaceText
set wrap to find stop
set match case to true
end tell
execute find findObject replace replace all
end tell
end ReplaceInRange
========================
After the first pass (the first call of remplacerLI function), the selection vanishes. I thought setting a range of text before calling it might resolve the problem, but this doesn't seem to work and the second call of the function remplacerLI applies to all the active document. I'm a little lost.