我可以通过UserForm从用户输入填充Word文档中的书签位置。
我想要做的是将输入的文本转换为超链接。
使用以下snippit代码将文本插入适当的位置:
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
任何建议都将不胜感激
提前致谢
答案 0 :(得分:0)
[main] ERROR de.anonymised.anonymised.anonymised.EntryPoint - Cannot connect to the database
com.microsoft.sqlserver.jdbc.SQLServerException: SQL Server did not return a response. The connection has been closed.
此行至少有两个问题,可能更多取决于您希望超链接链接到的内容。
您可以在此处找到更多信息:https://msdn.microsoft.com/en-us/library/office/ff837214(v=office.15).aspx
答案 1 :(得分:0)
我找到了更好的解决方案。对于那些需要的人,它发布在下面:
'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"
答案 2 :(得分:0)
仅提供对Jame答案的进一步描述。
'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
这是我的工作版本。在我的实例中,我在表格单元格中输入了像AC-2这样的文本,并使用AC2制作了书签。一个带有AC-2的表单击到另一个带有书签的带有AC-2的表。
{{1}}