sheriffdaone
New member
- Joined
- Oct 4, 2006
- Messages
- 3
- Programming Experience
- Beginner
Hi to everybody
I am trying to count the words in a word document and i tried different ways and eventually found a way to count them but it gives me "COMException".
VB.NET Source code look like this:
But it gives an COMException , "this method or property cannot be used , because there is no active window". And after i count the words i'll upload the file to a ftp but i can't get the result. With regular ways i can count them but cannot send them to ftp server, this time it gives me another "COMException" like, "this file in use". So is there another way to do it?
Thanks
Thanks
I am trying to count the words in a word document and i tried different ways and eventually found a way to count them but it gives me "COMException".
VB.NET Source code look like this:
VB.NET:
[FONT=Courier New]Public Function reader(ByVal filename As String) As Boolean [/FONT]
[FONT=Courier New]Dim saveFile As Object = filename + "_new.doc" [/FONT]
[FONT=Courier New]Dim max As Integer = 500 [/FONT]
[FONT=Courier New]Dim wordApp As Word.ApplicationClass = New Word.ApplicationClass [/FONT]
[FONT=Courier New]Dim file As Object = filename [/FONT]
[FONT=Courier New]Dim readOnly As Object = False [/FONT]
[FONT=Courier New]Dim isVisible As Object = False [/FONT]
[FONT=Courier New]Dim word_false As Object = False [/FONT]
[FONT=Courier New]Dim bos As Object = System.Reflection.Missing.Value [/FONT]
[FONT=Courier New]Dim doc As Word.Document = wordApp.Documents.Open(file, bos, readOnly, bos, bos, bos, bos, bos, bos, bos, bos, isVisible) [/FONT]
[FONT=Courier New]Dim sayilan As Word.WdStatistic = Word.WdStatistic.wdStatisticWords [/FONT]
[FONT=Courier New]Dim sayi As Integer = doc.ComputeStatistics(sayilan, bos) [/FONT]
[FONT=Courier New]Dim saveChanges As Object = Word.WdSaveOptions.wdDoNotSaveChanges [/FONT]
[FONT=Courier New]doc.Close(saveChanges, bos, bos) [/FONT]
[FONT=Courier New]wordApp.Quit(saveChanges, bos, bos) [/FONT]
[FONT=Courier New]If sayi > max Then [/FONT]
[FONT=Courier New] Return False [/FONT]
[FONT=Courier New]Else [/FONT]
[FONT=Courier New] Return True [/FONT]
[FONT=Courier New]End If [/FONT]
[FONT=Courier New]End Function[/FONT]
Thanks
Thanks