COMate example Demo-retrieve text from word doc using GetObj

Just starting out? Need help? Post your questions and find answers here.
Andi
User
User
Posts: 21
Joined: Fri Sep 12, 2008 2:43 pm
Location: Berlin

COMate example Demo-retrieve text from word doc using GetObj

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

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

Post 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?
Hygge
Andi
User
User
Posts: 21
Joined: Fri Sep 12, 2008 2:43 pm
Location: Berlin

Post 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".
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Andi, the example you mention gets a document object, not a Word application object! :wink:
I may look like a mule, but I'm not a complete ass.
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post 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
Hygge
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Ah yes, should have thought of that! :wink:

Nice one Kiffi.
I may look like a mule, but I'm not a complete ass.
Andi
User
User
Posts: 21
Joined: Fri Sep 12, 2008 2:43 pm
Location: Berlin

Post by Andi »

Thanks, Kiffi! (Ja, das ist genau das, was ich suchte!) :)
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

Now and then, just

Code: Select all

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

Regards, Little John
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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!
I may look like a mule, but I'm not a complete ass.
Post Reply