Character count for a word document with space

Hi All,
This is the code for finding the character count of a word document with space. Create a windows or console application. Add word reference to your application and try the following code. Drag a button,textbox and a open file dialog in your application and in the Select button,write the code for opening the word document and In the get button.write the code for getting the character count.Please don't forget to rate this code.

Private Sub btnget_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnget.Click

Dim wdStatisticWords As String = String.Empty
Dim wdStatisticCharactersWithSpaces As String = String.Empty
Dim wdStatisticCharacters As String = String.Empty
Dim wdStatisticPages As String = String.Empty
Dim wdStatisticLines As String = String.Empty
Dim wdStatisticWord As String = String.Empty
Dim WordCounts As Long = 0
Dim Pages As Long = 0
Dim lines As Long = 0
Dim pharagraph As Long = 0
Dim chars As Long = 0
Dim chwithspace As Long = 0
Dim WordWordCount As Long
Dim missing As Object = System.Reflection.Missing.Value

Dim wordApp As New Word.Application
Dim wordDoc As New Word.Document
wordDoc = wordApp.Documents.Open(ofd.FileName)
Dim stat As WdStatistic = WdStatistic.wdStatisticPages
chwithspace = chwithspace + wordDoc.ComputeStatistics(WdStatistic.wdStatisticCharactersWithSpaces)
lines = lines + wordDoc.ComputeStatistics(WdStatistic.wdStatisticLines)
Pages = Pages + wordDoc.ComputeStatistics(WdStatistic.wdStatisticPages)
chars = chars + wordDoc.ComputeStatistics(WdStatistic.wdStatisticCharacters)
WordCounts = WordCounts + wordDoc.ComputeStatistics(WdStatistic.wdStatisticWords)
MsgBox("WordCount " & WordCounts & vbCrLf & "Charcount with space " & chwithspace & vbCrLf & "Lines " & lines & vbCrLf & "Pages " & Pages)
Dim pr As New Process
pr = Process.GetCurrentProcess()
End Sub

Private Sub btnselect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnselect.Click
txfile.Text = ofd.FileName
txfile.ReadOnly = True
End Sub
End Class



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: