Word UserForm VBA:来自书签的超链接
我能够通过用户表单从用户输入填充Word文档上的书签位置 我想做的是将输入的文本转换为超链接 以下代码片段用于将文本插入适当位置:Word UserForm VBA:来自书签的超链接,vba,ms-word,Vba,Ms Word,我能够通过用户表单从用户输入填充Word文档上的书签位置 我想做的是将输入的文本转换为超链接 以下代码片段用于将文本插入适当位置: Private Sub CommandButton1_Click() Dim benchmarkURL As Range Set benchmarkURL = ActiveDocument.Bookmarks("benchmark").Range benchmarkURL.Text = Me.benchmarkURLTextBox.Valu
Private Sub CommandButton1_Click()
Dim benchmarkURL As Range
Set benchmarkURL = ActiveDocument.Bookmarks("benchmark").Range
benchmarkURL.Text = Me.benchmarkURLTextBox.Value
ActiveDocument.Bookmarks.Add "benchmark", benchmarkURL
Me.Repaint
'Update the fields to populate the references of the bookmarks
UpdateAllFields
UserForm1.Hide
End Sub
我尝试了以下不起作用的方法:
Private Sub CommandButton1_Click()
Dim benchmarkURL As Range
Set benchmarkURL = ActiveDocument.Bookmarks("benchmark").Range
benchmarkURL.Text = Me.benchmarkURLTextBox.Value
Hyperlinks.Add(ActiveDocument.Bookmarks.Add "benchmark", benchmarkURL)
Me.Repaint
'Update the fields to populate the references of the bookmarks
UpdateAllFields
UserForm1.Hide
End Sub
任何建议都将不胜感激
提前谢谢
Hyperlinks.Add(ActiveDocument.Bookmarks.Add "benchmark", benchmarkURL)
这一行至少有两个错误,可能更多地取决于您希望超链接链接到的内容
您可以在这里找到更多信息:我找到了更好的解决方案。对于那些需要的人,发布如下:
'URL of Benchmark Data
Dim benchmarkURL As Range
Set benchmarkURL = ActiveDocument.Bookmarks("benchmark").Range
benchmarkURL.Text = Me.benchmarkURLTextBox.Value
ActiveDocument.Hyperlinks.Add Anchor:=benchmarkURL, Address:= _
benchmarkURL.Text, SubAddress:="", ScreenTip:="", TextToDisplay:= _
"Benchmark Data"
只是为了对Jame的回答做进一步的描述
'URL of Benchmark Data
Dim benchmarkURL As Range
Set benchmarkURL = ActiveDocument.Bookmarks("benchmark").Range
benchmarkURL.Text = Me.benchmarkURLTextBox.Value
ActiveDocument.Hyperlinks.Add Anchor:=benchmarkURL, Address:=benchmarkURL.Text, SubAddress:="", ScreenTip:="", TextToDisplay:="Benchmark Data"
意思是把这些信息放进去
'URL of Benchmark Data
ActiveDocument.Hyperlinks.Add Anchor:=<<Where link will display>>, Address:= <<Where the link will go to>>, SubAddress:="", ScreenTip:="", TextToDisplay:="<<what the link text should say"
'/////////////
Set benchmarkURL = oDoc.Bookmarks(strText2).Range
With oDoc.Tables(r).Cell(i, 1)
.Range.Hyperlinks.Add Anchor:=oDoc.Tables(r).Cell(i, 1).Range, Address:="", SubAddress:=strText2, ScreenTip:="", TextToDisplay:=strText
End With