Page 1 of 1

Microsoft Office Automation using Comate

Posted: Tue May 24, 2016 6:33 pm
by PeteM
I'm having trouble navigating through a Word document using Comate Plus. Everything works fine, except the line noted to scroll down the page. If I record a macro in Word, the VBA code is:

Selection.MoveDown Unit:=wdScreen, Count:=1

I believe the wdScreen value is 7, which I have put in the code.

I've tried Invoke, SetProperty and GetIntegerProperty command variants, but I still can get the thing to scroll down.

Any help much appreciated!

Code: Select all

  WordObject = COMate_CreateObject("Word.Application")
  If WordObject 
    Document(Index) = WordObject\GetObjectProperty("Documents\Open('" + FileName + "', #opt, #True)")
    If Document(Index)
      WordObject\SetProperty("Visible = #True")
      WordObject\SetProperty("WindowState = 1") ; Maximize
      WordObject\SetProperty("ActiveDocument\Selection\MoveDown(Unit = 7, Count = 1)") ; Does not work
    Endif
  Endif


Re: Microsoft Office Automation using Comate

Posted: Tue May 24, 2016 9:29 pm
by IdeasVacuum
While you are waiting for an answer from somebody that knows what they are talking about, forgive me for throwing in a guess that is very probably wrong. What you are trying to do does not sound like a "property" to be set. Would "Invoke" be nearer to the required action?

Re: Microsoft Office Automation using Comate

Posted: Wed May 25, 2016 4:18 pm
by PeteM
Yes, I've tried that, but it didn't work either ...

Re: Microsoft Office Automation using Comate

Posted: Thu May 26, 2016 11:25 am
by spikey
I'm fairly certain that Comate doesn't support named arguments (although I can't find any evidence to support this one way or the other so I may be wrong).
I concur with IdeasVacuum on the Invoke though.

In which case:

Code: Select all

WordObject\SetProperty("ActiveDocument\Selection\MoveDown(Unit = 7, Count = 1)") ; Does not work
Should be:

Code: Select all

WordObject\Invoke("ActiveDocument\Selection\MoveDown(7, 1)")
Failing that add:

Code: Select all

Debug COMate_GetLastErrorDescription()
after the instruction to see if anything helpful is reported.

Re: Microsoft Office Automation using Comate

Posted: Thu May 26, 2016 3:46 pm
by PeteM
It returns "Method/property not supported by this object". :(

Re: Microsoft Office Automation using Comate

Posted: Thu May 26, 2016 3:50 pm
by PeteM
Not sure if its relevant but both of these commands *do* work ...

Code: Select all

ExcelObject\SetProperty("Visible = #True")
ExcelObject\SetProperty("ActiveWindow\WindowState = -4137")

Re: Microsoft Office Automation using Comate

Posted: Thu May 26, 2016 5:20 pm
by spikey
Unfortunately I don't have Word installed on this machine so I can't test this out for myself.

I see from the documentation that the syntax for the command has changed significantly in recent versions - which version of Word are you targeting?
It will make a big difference.