2014-01-24 49 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