Microsoft Word和AppleScript(更改标题)

时间:2011-05-10 18:50:05

标签: macos ms-word applescript

我有2个文件。我希望将第一个doc的标题复制到第二个doc(完全相同的格式,页码选项等)。这是我到目前为止的源代码:

tell application "Microsoft Word"
    activate
    open "Macintosh HD:test.docx"
    open "Macintosh HD:newtest.docx"
    set doc to document "Macintosh HD:test.docx"
    set doc2 to document "Macintosh HD:newtest.docx"

    set refHeader to get header of section 1 of doc index header footer primary

end tell

如何将refHeader设置为doc2的标题? 感谢。

我尝试了这个,但它不起作用,给我错误:

set refHeader to page number options of (get header of section 1 of doc index header footer primary)
    set page number options of (get header of section 1 of doc2 index header footer primary) to refHeader

1 个答案:

答案 0 :(得分:2)

这似乎相当精细,但这项工作可能是更好的方式,但我不确定

tell application "Microsoft Word"
    activate
    open "Macintosh HD:test.docx"
    open "Macintosh HD:newtest.docx"
    set doc to document "Macintosh HD:test.docx"
    set doc2 to document "Macintosh HD:newtest.docx"

    set refHeader to content of text object of (get header of section 1 of doc index header footer primary)
    set props to properties of text object of (get header of section 1 of doc index header footer primary)
    set content of text object of (get header of section 1 of doc2 index header footer primary) to refHeader
    set properties of text object of (get header of section 1 of doc2 index header footer primary) to props
end tell