How do i read specific paragraph with Comate

Everything else that doesn't fall into one of the other PB categories.
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

How do i read specific paragraph with Comate

Post 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
Regards
Leo
User avatar
Kiffi
Addict
Addict
Posts: 1526
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: How do i read specific paragraph with Comate

Post 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
Hygge
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

Re: How do i read specific paragraph with Comate

Post by leodh »

@ Kiffi

Thanks for that, It works perfectly.

All the best and Happy New Year.
Regards
Leo
Post Reply