Macro to delete bookmarks in word file.
I am using invoke code (vbnet):
'Add a reference to the Microsoft.Office.Interop.Word namespace in UiPath Studio
'Create an instance of the Word application
Dim objWord As New Microsoft.Office.Interop.Word.Application
'Open the document
Dim objDoc As Microsoft.Office.Interop.Word.Document = objWord.Documents.Open(“path\filname.docx”)
'Delete all bookmarks that start with an underscore
For Each bkm As Microsoft.Office.Interop.Word.Bookmark In objDoc.Bookmarks
If bkm.Name Like “_*” Then
bkm.Delete()
End If
Next
'Save and close the document
objDoc.Save()
objDoc.Close()
'Quit the Word application
objWord.Quit()
'Release the objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(objDoc)
System.Runtime.InteropServices.Marshal.ReleaseComObject(objWord)
objDoc = Nothing
objWord = Nothing
- The bookmarks are not deleted.
- Tried running macros in excel, no compilation error, still bookmarks are not deleted.
Unable to understand what mistake am I making in the code. If you know any other method apart from the above please let me.