Dear support team,
Kindly provide VB.Net script for removing all hyperlinks from Word doc and saving changes to same file.
Thank you!
Dim document As New Document()
document.LoadFromFile("test.docx")
Dim hyperlinks As New List(Of Field)()
For Each section As Section In document.Sections
For Each sec As DocumentObject In section.Body.ChildObjects
If sec.DocumentObjectType = DocumentObjectType.Paragraph Then
Dim objs = (TryCast(sec, Paragraph)).ChildObjects
Dim i As Integer = 0
Do While i < objs.Count
If objs(i).DocumentObjectType = DocumentObjectType.Field Then
Dim field As Field = TryCast(objs(i), Field)
If field.Type = FieldType.FieldHyperlink Then
'remove hyperlink and keep text
Dim txt = field.FieldText
Dim tr As New TextRange(document)
tr.Text = txt
objs.RemoveAt(i)
objs.Insert(i,tr)
End If
End If
i += 1
Loop
End If
Next sec
Next section
document.SaveToFile("removelink.docx",FileFormat.Docx2010)