In this article we will discuss read
and rewrite or update document properties of any word document in vb.net. Every
word document has some inbuilt properties and custom properties such as Title,
subject, category, Author, comments etc.
You can see or set the document
properties by opening Advance Document properties section just like if you are
working on word 2010 you will see this like:
Advance Document
properties:

In this article we will read and set these properties and will learn that how to
make custom properties of any word document.
So let start with taking a windows
form and design like this:
And then we need to add some
reference:
Microsoft.office.Core
Microsoft.Office.Interop.Word
Code:
Make two private object
Private
Wapp As Word.Application
Private
docWord As Word.Document
Write code on the browse button click
event
Create OpenFileDialog object and set
the filter for word documents.
Dim
dlg As New
OpenFileDialog
dlg.Filter =
"Word document |*.doc;*.docx"
If
dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
Initialize word application class and
word document objects
If
Wapp Is Nothing Then
Wapp =
New Word.Application
End If
If
docWord Is Nothing Then
docWord =
New Word.Document
Else
docWord.Close()
End If
Use Documents.oopen() method for
opening word document and use BuiltInDocumentProperties property for retrieving
its inbuilt advanced properties.
docWord =
Wapp.Documents.Open(dlg.FileName)
Dim
_BuiltInProperties As Object = docWord.BuiltInDocumentProperties
If Not _BuiltInProperties
Is Nothing Then
txtTitle.Text = _BuiltInProperties("Title").Value
txtSubject.Text = _BuiltInProperties("Subject").Value
txtAuthor.Text = _BuiltInProperties("Author").Value
txtManager.Text = _BuiltInProperties("Manager").Value
txtCompany.Text = _BuiltInProperties("Company").Value
txtCategory.Text = _BuiltInProperties("Category").Value
txtKeyWords.Text = _BuiltInProperties("Keywords").Value
txtComment.Text = _BuiltInProperties("Comments").Value
End If
End If
For updating Inbuilt properties add
code on Update button click event
Dim
_BuiltInProperties As Object = docWord.BuiltInDocumentProperties
If Not _BuiltInProperties
Is Nothing Then
_BuiltInProperties("Title").Value
= txtTitle.Text.Trim()
_BuiltInProperties("Subject").Value
= txtSubject.Text.Trim()
_BuiltInProperties("Author").Value
= txtAuthor.Text.Trim()
_BuiltInProperties("Manager").Value
= txtManager.Text.Trim()
_BuiltInProperties("Company").Value
= txtCompany.Text.Trim()
_BuiltInProperties("Category").Value
= txtCategory.Text.Trim()
_BuiltInProperties("Keywords").Value
= txtKeyWords.Text.Trim()
_BuiltInProperties("Comments").Value
= txtComment.Text.Trim()
End If
MessageBox.Show("Summery
has been updated successfully")
If Not docWord Is Nothing Then
docWord.Close()
End If
If Not Wapp Is Nothing Then
Wapp.Quit()
End If