ReplaceEverywhere("<$search$>", "<$replace$>")

on ReplaceEverywhere(findText, replaceText)
	local theShape, theRange, theHeaderFooters, theHeaderFooter
	tell application "Microsoft Word"
		--first find and replace in the body (main story) of document
		set theRange to text object of active document
		my ReplaceInRange(findText, replaceText, theRange)

		--nowin all shapes
		set allShapes to (every shape of active document)
		repeat with theShape in allShapes
			set theTextFrame to (text frame of theShape)
			if has text of (text frame of theShape) then
				--note:'text range', not 'text object' of text frame
				set theRange to text range of text frame of theShape
				my ReplaceInRange(findText, replaceText, theRange)
			end if
		end repeat
		
		-- now in the headers and footers of each section
		set allSections to every section of active document
		repeat with theSection in allSections
			set theHeaderFooters to {get header theSection index header footer primary} & {get header theSection index header footer first page} & {get header theSection index header footer even pages} & {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 theHeaderFooter in theHeaderFooters
				set theRange to text object of theHeaderFooter
                if count of characters in theRange is greater than 1
                    my ReplaceInRange(findText, replaceText, theRange)
				end if
				--now in their shapes
				set allShapes to (every shape of theHeaderFooter)
				repeat with theShape in allShapes
					if has text of (text frame of theShape) then
						--note:'text range', not 'text object' of text frame
						set theRange to text range of text frame of theShape
                        set tobject to text object in theRange
                        if (count of characters in tobject) is greater than 1 then
                            my ReplaceInRange(findText, replaceText, theRange)
                        end if
					end if
				end repeat
			end repeat
		end repeat
	end tell
end ReplaceEverywhere

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
		tell the active document to execute find findObject replace replace all
	end tell
end ReplaceInRange

