使用vb.net在单词中添加超链接 [英] Adding a hyperlink in word, with vb.net

查看:133
本文介绍了使用vb.net在单词中添加超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试通过VB程序在单词中添加指向web url的超链接。我磕磕绊绊地试着找到正确的语法和我需要做的事情,因为我已经得到了很多无用的VBA示例,这根本不是我需要的。

I'm currently trying to add a hyperlink to a web url in word through a VB program. I'm stumbling around to try and find the proper syntax and what I need to accomplish this, because I've been getting a lot of unhelpful VBA examples, which is not what I need at all.

我的代码如下所示:

sPara2 = oDoc.Content.Paragraphs.Add
sPara2.Range.Text = attachmentRdr("attachmentName")
sPara2.Range.Hyperlinks.Add(attachmentRdr("attachmentPath"))
sPara2.Format.SpaceAfter = 24    '24 pt spacing after paragraph.
sPara2.Range.InsertParagraphAfter()

其中 attachmentRdr 是一个 sqlDatareader 从数据库中读取文本字符串(附件名称和路径)。如果我运行这个,我得到一个错误的参数错误(从'code> hyperlinks.add()获得'程序。)

where attachmentRdr is a sqlDatareader reading strings of text (attachment name, and path) from a database. If I run this, I get an error for bad parameters (which gets' proced off of the hyperlinks.add()).

推荐答案

将范围作为第一个参数传递给添加功能,然后传递您的网址:

Pass range through as the first parameter to the Add function, followed by your URL:

Dim range As Microsoft.Office.Interop.Word.Range
range = Me.Application.Selection.Range
range.Hyperlinks.Add(range, "http://www.microsoft.com")

这篇关于使用vb.net在单词中添加超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆