CodeYou have already tested it. Add the try catch Statement by yourself. Remember to release the resource after an error occurs.
After this operation is performed, the operated tag will be removed.
Code
Private Void Button#click ( Object Sender, eventargs E)
{
Clearbookmarkfromdoc (@"C: \ test.doc","A");
}
Public Void Clearbookmarkfromdoc ( String Filepath, String Bkname)
{
Object Filepath = Filepath As Object ;
Object Missing = Type. missing;
Object Objtrue = True As Object ;
// Create a word. Application
Microsoft. Office. InterOP. Word. Application mywordapp = New Microsoft. Office. InterOP. Word. applicationclass ();
Microsoft. Office. InterOP. Word. Document myworddoc = Mywordapp. Documents. Open ( Ref Filepath, Ref Missing, Ref Missing, Ref Missing,
Ref Missing, Ref Missing, Ref Missing, Ref Missing,
Ref Missing, Ref Missing, Ref Missing, Ref Missing,
Ref Missing, Ref Missing, Ref Missing, Ref Missing );
Microsoft. Office. InterOP. Word. Range bmrange = Default (Microsoft. Office. InterOP. Word. Range );
Microsoft. Office. InterOP. Word. bookmarks bkmrs = Myworddoc. bookmarks;
Object Bkindex = Bkname As Object ;
Microsoft. Office. InterOP. Word. Bookmark BKM = Bkmrs. get_item ( Ref Bkindex );
Textbox1.text = BKM. Name;
BKM. range. Text = String . Empty;
Myworddoc. Save ();
Myworddoc. Close ( Ref Objtrue, Ref Missing, Ref Missing );
Mywordapp. Quit ( Ref Objtrue, Ref Missing, Ref Missing );
}