Adding a hyperlink in word, with vb.net

断了今生、忘了曾经 提交于 2019-12-22 08:12:23

问题


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.

My code looks like this:

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()

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()).


回答1:


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")


来源:https://stackoverflow.com/questions/14389464/adding-a-hyperlink-in-word-with-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!