2017-03-01 9 views
0

ユーザーフォームからユーザーフォームからWord文書にブックマークされた場所を入力できます。Word UserForm VBA:ブックマークからのハイパーリンク

ハイパーリンクに入力されたテキストを変換します。

次のコード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
Hyperlinks.Add(ActiveDocument.Bookmarks.Add "benchmark", benchmarkURL) 

この行には少なくとも2つの問題があります。おそらく、ハイパーリンクのリンク先によります。

  1. ActiveDocumentにする必要があるハイパーリンクの親オブジェクトを省略しました。
  2. 戻り値 のHyperlinks.Addが割り当てられていないため、角かっこは使用しないでください。

あなたはここにさらに情報を見つけることができます:https://msdn.microsoft.com/en-us/library/office/ff837214(v=office.15).aspx

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" 
関連する問題