Page 1 of 1

COMate example Demo-retrieve text from word doc using GetObj

Posted: Wed Nov 26, 2008 5:16 pm
by Andi
Hi, the example mentioned above works fine. But how can I make the document visible which was opened in this way? My guess was, to comment out the line "WordDocObject\Release()". But this results only in a document with a totally empty grey "text field", in which you even can't insert text. - Thanks.

Re: COMate example Demo-retrieve text from word doc using Ge

Posted: Wed Nov 26, 2008 5:53 pm
by Kiffi
Andi wrote:Hi, the example mentioned above works fine. But how can I make the document visible which was opened in this way?
do you mean something like this:

Code: Select all

Define.COMateObject WordApplication

MyWordDoc$ = "C:\Programme\Microsoft ActiveSync\readme.doc"

WordApplication = COMate_CreateObject("Word.Application")

If WordApplication
  WordApplication\Invoke("Documents\Open('" +MyWordDoc$ + "')")
  WordApplication\SetProperty("Visible=#True")
  MessageRequester("", "Word is visible now. Press OK to quit Word")
  WordApplication\Invoke("Quit")
  WordApplication\Release()
Else
  MessageRequester("COMate", "Couldn't create WordApplication!")
EndIf
Greetings ... Kiffi

P.S.: Andi, wieso fragste nicht im deutschen Forum?

Posted: Wed Nov 26, 2008 6:06 pm
by Andi
@Kiffi: Sure, I could have asked in the German forum. But I thought, the members of the German forum are also members of the English forum but not vice versa. That is the only reason.

With regard to your example: Yes, I know that I can use the Invoke()-method to open a document. But I try to do the same with the GetObject()-method. The reason is, that after closing a document, which was opened via the Invoke-method, the Word menu bar is "frozen".

Posted: Wed Nov 26, 2008 8:39 pm
by srod
Andi, the example you mention gets a document object, not a Word application object! :wink:

Posted: Wed Nov 26, 2008 9:16 pm
by Kiffi
@Andi: The following example uses GetObject() (ist es das, was Du suchtest?):

Code: Select all

Define.COMateObject WordDocObject

MyWordDoc$ = "c:\My.doc"

WordDocObject = COMate_GetObject(MyWordDoc$, "Word.Document")

If WordDocObject
  WordDocObject\SetProperty("Application\Visible = #True")
  text$ = WordDocObject\GetStringProperty("Range\Text")
  MessageRequester("", "Word is visible now. Press OK to quit Word")
  WordDocObject\Invoke("Application\Quit")
  WordDocObject\Release()
  MessageRequester("COMate -Get text from word document!", text$)  ;Would be better off placing this text in an Editor gadget.
Else
  MessageRequester("COMate -Get text from word document!", "Couldn't create the document object!")
EndIf
Greetings ... Kiffi

Posted: Wed Nov 26, 2008 9:22 pm
by srod
Ah yes, should have thought of that! :wink:

Nice one Kiffi.

Posted: Wed Nov 26, 2008 11:11 pm
by Andi
Thanks, Kiffi! (Ja, das ist genau das, was ich suchte!) :)

Posted: Thu Nov 27, 2008 1:35 am
by Little John
Now and then, just

Code: Select all

RunProgram("c:\my.doc")
might be sufficient. ;-)

Regards, Little John

Posted: Thu Nov 27, 2008 11:31 am
by srod
Little John wrote:Now and then, just

Code: Select all

RunProgram("c:\my.doc")
might be sufficient. ;-)

Regards, Little John
Actually that is not a bad idea; use RunProgram() and then COMate_GetObject() to retrieve the worksheet object etc. Yes that should work just as well! :)

Often the simplest things are the most overlooked!