【问题标题】:Adding a hyperlink in word, with vb.net用 vb.net 在 word 中添加超链接
【发布时间】:2013-01-01 14:31:14
【问题描述】:

我目前正在尝试通过 VB 程序将超链接添加到 word 中的 web url。我正在跌跌撞撞地尝试找到正确的语法以及完成此操作所需的内容,因为我得到了很多无用的 VBA 示例,这根本不是我需要的。

我的代码如下所示:

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

其中attachmentRdrsqlDatareader 从数据库读取文本字符串(附件名称和路径)。如果我运行它,我会收到错误参数的错误(从hyperlinks.add() 处理)。

【问题讨论】:

    标签: vb.net hyperlink word-2010


    【解决方案1】:

    将范围作为第一个参数传递给 Add 函数,然后是您的 URL:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      相关资源
      最近更新 更多