Hello,
I adapted a script to replace text in the footers of a whole buncha Microsoft Word docs. The replacement text requires a soft return. When I place a “\n” where the soft return should go, Script Editor deletes the characters and shows me the text as if a soft return was placed there. However, Microsoft doesn’t detect a soft return.
Here is the script:
display dialog "Please navigate to your Word template"
set myTemplate to (choose file) as string
on ReplaceInFooters(findText, replaceText)
local theShape, theRange, theFooters, theFooter
tell application "Microsoft Word"
-- now in the headers and footers of each section
set allSections to every section of active document
repeat with theSection in allSections
set theFooters to {get footer theSection index header footer primary} & {get footer theSection index header footer first page} & {get footer theSection index header footer even pages}
repeat with theFooter in theFooters
set theRange to text object of theFooter
my ReplaceInRange(findText, replaceText, theRange)
end repeat
end repeat
end tell
end ReplaceInFooters
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
end tell
execute find findObject replace replace all
end tell
end ReplaceInRange
display dialog "Microsoft Word must be running to use this script."
set this_folder to (choose folder with prompt "Pick the folder containing the files to process:") as string
tell application "System Events"
set these_files to every file of folder this_folder
end tell
with timeout of 1200 seconds
repeat with i from 1 to the count of these_files
set this_file to (item i of these_files as alias)
set this_info to info for this_file
if visible of this_info is true and alias of this_info is false then
tell application "Microsoft Word"
open this_file
tell active document
set update styles on open to true
set attached template to myTemplate
my ReplaceInFooters("Original content Copyright © by Holt, Rinehart and Winston. Additions and changes to the original content are the responsibility of the instructor.", "Original content Copyright © by Holt, Rinehart and Winston; a Division of Houghton Mifflin Harcourt Publishing Company.
Additions and changes to the original content are the responsibility of the instructor.")
my ReplaceInFooters("Copyright © by Holt, Rinehart and Winston. All rights reserved.", "Original content Copyright © by Holt, Rinehart and Winston; a Division of Houghton Mifflin Harcourt Publishing Company.
Additions and changes to the original content are the responsibility of the instructor.")
my ReplaceInFooters("Copyright © by Holt, Rinehart and Winston. All rights reserved", "Original content Copyright © by Holt, Rinehart and Winston; a Division of Houghton Mifflin Harcourt Publishing Company.
Additions and changes to the original content are the responsibility of the instructor.")
end tell
close active document saving yes
end tell
end if
end repeat
end timeout
What should I be doing instead?