新的Word超链接的颜色是黑色,我想把它变成蓝色



我是Word的vba业余爱好者。我的宏(下图)从选定的文本创建了一个超链接,但是新的超链接是黑色的,而我用Word的菜单创建的超链接是蓝色的。我希望我的宏创建的超链接是蓝色的太。正如您将在我的宏(下面)中看到的那样,我无法将超链接变为蓝色。如有任何建议,不胜感激。

        Marc

宏:

Sub subHyprlinkSrch4PdfFiles_aaa()
'
' subHyprlinkSrch4PdfFiles_aaa Macro
'
'
    Dim strTextToDisplay As String
    Dim rngSelection As RAnge
    Selection.MoveDown Unit:=wdLine, Count:=2
    Selection.MoveLeft Unit:=wdCharacter, Count:=5
    Selection.MoveLeft Unit:=wdCharacter, Count:=9, Extend:=wdExtend
    Set rngSelection = ActiveDocument.Selection.RAnge
    Application.Selection.Font.ColorIndex = wdBlue
    strTextToDisplay = Application.Selection.Text
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.RAnge, Address:="" _
        , SubAddress:="", ScreenTip:="", TextToDisplay:=strTextToDisplay
    Application.Selection.Style = wdStyleHyperlink
    Application.Selection.Font.ColorIndex = wdBlue
    With rngSelection
        .Font.ColorIndex = wdBlue
    End With

End Sub 'subHyprlinkSrch4PdfFiles_aaa()

这是我用用户Don Jewett昨天(2016年11月2日)给我的解决方案修复的子节点:

Sub subHyperlinkSelectedTextaaa() 'Hyperlink  to a file whatever text you selected.
    'Hyperlink  to a file whatever text you selected.
    ' http://www.wiseowl.co.uk/blog/s209/type-filedialog.htm
    Dim Sel01 As Selection
    Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    Dim iFileChosen As Integer
    Dim strFileFullname As String
    Dim Txt2Display As String

    Set Sel01 = Application.Selection
    If Sel01.Type <> wdSelectionIP Then ' i.e., if the selection is valid, i.e., characters are selected
        Txt2Display = Sel01.Text
        'MsgBox Txt2Display
    Else
        MsgBox "No characters were selected validly; so this macro will terminate now."
        Exit Sub
    End If 'If Sel01.Type <> wdSelectionIP Then ' i.e., if the selection is valid, i.e., characters are selected

    ' Open FileDialog "fd" and select a file
    iFileChosen = fd.Show
        If iFileChosen <> -1 Then
            'You didn't choose anything (clicked on CANCEL)
            MsgBox "You chose cancel, or something prevented the file-selection-dialog from operating property."
        Else
            strFileFullname = CStr(fd.SelectedItems(1))
            'MsgBox strFileFullname
        End If

    ' http://stackoverflow.com/questions/40388765/color-of-new-ms-word-hyperlink-is-black-and-i-want-it-to-be-blue
    With Application.Selection
        .Font.ColorIndex = wdBlue
        'ActiveDocument.Hyperlinks.Add Selection.Range, .Text, "", "", .Text
        ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
           strFileFullname, SubAddress:="", ScreenTip:="", TextToDisplay:=Txt2Display
        .Style = wdStyleHyperlink
    End With

End Sub 'subHyperlinkSelectedTextaaa()

如果你想创建一个使用选定文本作为链接和文本的超链接,这应该可以正常工作:

Sub subHyprlinkSrch4PdfFiles_aaa()
    With Application.Selection
        .Font.ColorIndex = wdBlue
        ActiveDocument.Hyperlinks.Add Selection.Range, .Text, "", "", .Text
        .Style = wdStyleHyperlink
    End With
End Sub

最新更新