2014-01-24 99 views
0

我試圖在Word評論中添加超鏈接對象。 要創建我用這一段腳本的活動文檔中一個新評論:Applescript插入超鏈接到MSWord評論

告訴應用程序「Microsoft Word中」 集tempString爲「Lorem存有」 使在選擇與性能{註釋文本新的Word評論: tempString} end tell

但是現在我無法獲得對創建的新評論的引用,因此無法使用它與「make new hyperlink object」命令一起使用。

感謝您的任何建議。

裏卡多

回答

0

我不認爲你可以通過返回的對象的工作做出新的Word評論(至少在這種情況下),你必須插入一個獨特的,可查找的字符串,然後通過迭代評論:

tell application "Microsoft Word" 
    -- insert a unique string 
    set tempString to (ASCII character 127) 
    set theComments to the Word comments of the active document 
    repeat with theComment in theComments 
     if the content of the comment text of theComment = tempString then 
      set theRange to the comment text of theComment 
      -- you do not have to "set theHyperlink". "make new" is enough 
      set theHyperlink to make new hyperlink object at theRange with properties {text range:theRange, hyperlink address:"http://www.google.com", text to display:"HERE", screen tip:"click to search Google"} 
      insert text "You can search the web " at theRange 
      exit repeat 
     end if 
    end repeat 
end tell 

(編輯插入超鏈接之前的一些文字。如果你想超鏈接後插入文本,還可以使用「插入文本‘文本’在theRange結束。)。

因此,對於添加文本,畢竟使用「顯而易見」就足夠了。

[ 對於其他人的查找此答覆。在Applescript中使用Word範圍的基本問題是每次嘗試重新定義評論故事中的範圍都會導致主文檔故事中出現一個範圍。好吧,我可能沒有嘗試過任何可能的方法,但是例如摺疊範圍,移動範圍的開始等等導致該問題。在過去,我也注意到,與其他故事範圍一樣,但還沒有就此進行調查。

此外,我懷疑你不能設置範圍到你剛創建的Word評論的原因是因爲評論的屬性指定了某種範圍的對象,我認爲它是一個臨時對象,可能會被銷燬立即創建後。所以試圖引用剛剛創建的對象不起作用。

應答的這一部分被修改......

最後,我發現來填充「內容豐富」評論的唯一另一種方式是在一個已知的地方插入文檔中的內容,然後複製其格式化的文本到評論,例如如果「爲人所知的就是選擇,你可以,如果你使用的是Word版本支持VBA以及AppleScript的通過

set the formatted text of the comment text of theComment to the formatted text of the text object of the selection 

設置theComment的內容,我實在看不出任何技術這就是爲什麼你不應該調用VBA來完成這些棘手的事情,即使你需要主代碼成爲Applescript。 ]

+0

而如何在評論「一些文本」的末尾插入超鏈接,以便鏈接只覆蓋評論文本的一部分? – user3021640

+0

當然:)。我試圖插入一系列評論如下: – user3021640

+0

當然:)。我正在嘗試插入一系列評論,如下所示:「您可以在網上搜索HERE」,其中「HERE」是代表www.google.com的超鏈接。希望更清楚。 – user3021640

0

最後我得到了一個解決方案在這裏:

https://discussions.apple.com/message/24628799#24628799

,讓我插入參考的超級鏈接與註釋文本的一部分,具有以下行,如果有人將來會搜索相同:

tell application "Microsoft Word" 

     set wc to make new Word comment at end of document 1 with properties {comment text:"some text"} 
     set ct to comment text of wc 
     set lastChar to last character of ct 
     make new hyperlink object at end of document 1 with properties {hyperlink address:"http://www.example.com", text object:lastChar} 

end tell