How do you remove hyperlinks from a Microsoft Word document?

前端 未结 2 606
挽巷
挽巷 2021-01-25 06:45

I\'m writing a VB Macro to do some processing of documents for my work. The lines of text are searched and the bracketed text is put in a list(box).

The problem comes w

2条回答
  •  自闭症患者
    2021-01-25 07:18

    The line removing the hyperlink is commented out. The following line will remove the first hyperlink within the selected range:

    Selection.Range.Hyperlinks(1).Delete
    

    This will also decrement Selection.Range.Hyperlinks.Count by 1.

    To see how the count of links is changing you can run the following method on a document:

    Sub AddAndRemoveHyperlink()
    
        Dim oRange As Range
        Set oRange = ActiveDocument.Range
        oRange.Collapse wdCollapseStart
        oRange.MoveEnd wdCharacter
    
        Debug.Print ActiveDocument.Range.Hyperlinks.Count
    
        ActiveDocument.Hyperlinks.Add oRange, "http://www.example.com"
        Debug.Print ActiveDocument.Range.Hyperlinks.Count
    
        ActiveDocument.Hyperlinks.Item(1).Delete
        Debug.Print ActiveDocument.Range.Hyperlinks.Count
    
    End Sub
    

提交回复
热议问题