Code seems to be OK, but need some corrections:
Using early binding
Dim sFileName As String = "C:\Test.doc"
Dim docapp As New Word.Application
Dim doc As Word.Document = docapp.Documents.Open(sFileName)
Dim para_tag As Word.Paragraph
Dim paracount As Integer
For Each para_tag In doc.Paragraphs
paracount += 1
MsgBox(para_tag.Style.ToString(), MsgBoxStyle.OKOnly, "Para no.:" & paracount.ToString())
Next
Using late binding
Dim sFileName As String = "C:\Test.doc"
Dim docapp As Object = CreateObject("Word.Application")
Dim doc As Object = docapp.Documents.Open(sFileName)
Dim para_tag As Object
Dim paracount As Integer
For Each para_tag In doc.Paragraphs
paracount += 1
MsgBox(para_tag.Style.ToString(), MsgBoxStyle.OKOnly, "Para no.:" & paracount.ToString())
Next
I suggest you to add
Try...Catch...End Try[
^] block.
[EDIT]
Ok, test it:
Module Module1
Sub Main()
Dim sFileName As String = "C:\MyDocument.doc"
EnumWrdPara(sFileName)
Console.ReadKey()
End Sub
Sub EnumWrdPara(sDocFullName AS String)
Dim docapp As Object = Nothing
Dim doc As Object = Nothing
Dim para_tag As Object = Nothing
Dim paracount As Integer = 0
Try
docapp = CreateObject("Word.Application")
doc = docapp.Documents.Open(sDocFullName)
For Each para_tag In doc.Paragraphs
paracount += 1
Console.WriteLine("Paragraph no.: {0} - style: (1)", paracount.ToString(), para_tag.Style.ToString)
Next
Catch ex As System.NullReferenceException
Console.WriteLine(ex.Message)
Catch ex As IO.IOException
Console.WriteLine(ex.Message)
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
para_tag = Nothing
doc.Close(SaveChanges:=False)
doc = Nothing
docapp.Quit()
docapp = Nothing
End Try
End Sub
End Module
It works, it has been checked. ;)
[/EDIT]