使用 Ruby 将超链接添加到 Word 文档网中创建的书签

发布于 2024-07-08 14:34:55 字数 317 浏览 5 评论 0原文

如何使用现有书签将超链接添加到 Word 文档。 我一直在使用 IRB 进行测试,但仍然出现命令失败。 我已附加到正在运行的 Word 应用程序,并选择了要绑定到超链接的文本。 为了进行测试,我一直在尝试添加一个谷歌超级链接。 我想一旦我明白了,我就能找到书签。 这是我正在使用的命令

doc.Hyperlink.add(word.selection, 'http://www.google.com', '','','text to display') 

两个空白参数分别用于子地址和屏幕提示。

How do you add a Hyperlink to a word document using an existing bookmark. I have been testing using IRB but continue to get Command Failed.
I have attached to a running word application have text selected that I want to tie to the hyperlink. For testing I have been trying to just add a google hyperlnk. I figure once I get that then I would be able to figure out the bookmark. This is the command I am using

doc.Hyperlink.add(word.selection, 'http://www.google.com', '','','text to display') 

The two blank parms are for SubAddress and ScreenTip respectivly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国产ˉ祖宗 2024-07-15 14:34:55

Luke-

你非常接近...

更改此......

  doc.Hyperlink.add(word.selection, 'http://www.google.com', '','','text to display')

至此...

  doc.Hyperlinks.add(word.selection.Range, 'http://www.google.com', '','','text to display')

有两个必要的更改:

(1) 您在超链接(复数)上调用 Add 方法集合,并且 (2) 第一个参数必须是 Range 对象。

通过这些更改,您的代码对我有用。

Luke-

You're very close...

Change this...

  doc.Hyperlink.add(word.selection, 'http://www.google.com', '','','text to display')

...to this...

  doc.Hyperlinks.add(word.selection.Range, 'http://www.google.com', '','','text to display')

There were two changes necessary:

(1) You call the Add method on the Hyperlinks (plural) collection, and (2) the first argument needs to be a Range object.

With these changes, your code works for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文