Page 1 of 1

How do i read specific paragraph with Comate

Posted: Thu Jan 03, 2013 7:57 am
by leodh
Hi,

I am trying to find the best way to read a specific paragraph from a word document, I was hoping to use Comate Plus but the only way I can do it is by reading the whole document and then finding the Paragraph that I require. As the documents are very large it is very slow to do it this way. I thought I saw a way of reading just one paragraph in Comate but I can not find it. I have tried to figure it out but I just can not get it to work.
I know the paragraph number or I can get it from a table in the document.

Does anyone have some working code I can have a look at.

Thanks

Re: How do i read specific paragraph with Comate

Posted: Thu Jan 03, 2013 8:04 pm
by Kiffi

Code: Select all

IncludePath "[YourPathTo]\COMatePLUS\"
XIncludeFile "COMatePLUS.pbi"

Procedure ShowErrorIfAny() 
  If COMate_GetLastErrorCode() : Debug COMate_GetLastErrorDescription() : EndIf 
EndProcedure 

Define WordApplication.COMateObject
Define WordDocument.COMateObject
Define WordParagraph.COMateObject

WordApplication = COMate_CreateObject("Word.Application") 

If WordApplication 
	
	WordDocument = WordApplication\GetObjectProperty("Documents\Open('[Your.Doc]')")
	
	If WordDocument
		
		AmountOfParagraphs = WordDocument\GetIntegerProperty("Paragraphs\Count")
		
		For ParagraphCounter = 1 To AmountOfParagraphs
			
			WordParagraph = WordDocument\GetObjectProperty("Paragraphs(" + Str(ParagraphCounter) + ")")
			
			If WordParagraph
				
				Debug WordParagraph\GetStringProperty("Range\Text")
				WordParagraph\Release()
				
			Else
				
				Debug "!WordParagraph"
				ShowErrorIfAny()
				
			EndIf
			
		Next
		
		WordDocument\Release()
		
	Else
		
		Debug "!WordDocument"
		ShowErrorIfAny()
		
	EndIf
	
	WordApplication\Invoke("Quit")
	WordApplication\Release()
	
Else
	
	Debug "!WordApplication"
	ShowErrorIfAny()
	
EndIf
Greetings ... Kiffi

Re: How do i read specific paragraph with Comate

Posted: Fri Jan 04, 2013 2:22 am
by leodh
@ Kiffi

Thanks for that, It works perfectly.

All the best and Happy New Year.