Microsoft Office Automation using Comate

Just starting out? Need help? Post your questions and find answers here.
PeteM
User
User
Posts: 12
Joined: Thu Mar 05, 2015 8:44 pm

Microsoft Office Automation using Comate

Post 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

IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Microsoft Office Automation using Comate

Post 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?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
PeteM
User
User
Posts: 12
Joined: Thu Mar 05, 2015 8:44 pm

Re: Microsoft Office Automation using Comate

Post by PeteM »

Yes, I've tried that, but it didn't work either ...
User avatar
spikey
Enthusiast
Enthusiast
Posts: 771
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Microsoft Office Automation using Comate

Post 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.
PeteM
User
User
Posts: 12
Joined: Thu Mar 05, 2015 8:44 pm

Re: Microsoft Office Automation using Comate

Post by PeteM »

It returns "Method/property not supported by this object". :(
PeteM
User
User
Posts: 12
Joined: Thu Mar 05, 2015 8:44 pm

Re: Microsoft Office Automation using Comate

Post 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")
User avatar
spikey
Enthusiast
Enthusiast
Posts: 771
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Microsoft Office Automation using Comate

Post 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.
Post Reply