COMatePlus question [SOLVED]

Just starting out? Need help? Post your questions and find answers here.
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

COMatePlus question [SOLVED]

Post by captain_skank »

Morning all,

Probably a stoopid question....

When I use COMate to generate a spreadsheet in excel, how do I get excel to get the focus/bring it to the front ?

At the moment excel opens but only as an icon on the taskbar, which has to clicked on to bring it to the front.

Any help appreciated

Cheers
Last edited by captain_skank on Thu Aug 06, 2020 3:25 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 6866
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: COMatePlus question

Post by infratec »

Code: Select all

Handle=FindWindow_(#Null, "excel or what ever the name of the window is")
If Handle
   ShowWindow_(Handle,#SW_RESTORE)
EndIf
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: COMatePlus question

Post by captain_skank »

Thanks for the reply Infratec.

Ahh great minds, I was just mucking about with findwindow.

But....

Excel doesn't always open with the same window name so I thought just using the handle would work.

But...

How can i get the handle from ComatePlus ?

I tried using ExcelObject as the handle

Code: Select all

ExcelObject = COMate_CreateObject("Excel.Application")
, but that's not a handle.

Again thanks for the help
User avatar
spikey
Enthusiast
Enthusiast
Posts: 586
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: COMatePlus question

Post by spikey »

I haven't tried it so I can't say if it definitely works with COMate (but I can't really see any reason why it shouldn't work)...
The Excel COM defines 'Application.hWnd' - have you tried getting it and using this with ShowWindow_?
See https://docs.microsoft.com/en-us/office ... ation.hwnd
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: COMatePlus question

Post by captain_skank »

Thanks Spikey.

What comate command do i use to get execute that and get a return value.?

I tried

Code: Select all

ExcelObject\Invoke("Application.hWnd") 
and all the iterations of

Code: Select all

Get_x_ Property
cheers
User avatar
spikey
Enthusiast
Enthusiast
Posts: 586
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: COMatePlus question

Post by spikey »

You should be able to retrieve it with:

Code: Select all

Handle = ExcelObject\GetIntegerProperty("hWnd")
If that doesn't work, post the results of this after the Get:-

Code: Select all

Debug COMate_GetLastErrorCode() 
Debug COMate_GetLastErrorDescription() 
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: COMatePlus question

Post by Marc56us »

When I use COMate to generate a spreadsheet in excel, how do I get excel to get the focus/bring it to the front ?
At the moment excel opens but only as an icon on the taskbar, which has to clicked on to bring it to the front.

Code: Select all

ExcelObject\SetProperty("Visible = #True")

Code: Select all

; Sample from COMatePLUS.chm
; Modified

XIncludeFile "COMatePLUS.pbi"

Define.COMateObject ExcelObject, WorkBook
ExcelObject = COMate_CreateObject("Excel.Application")

If ExcelObject
    If ExcelObject\SetProperty("Visible = #True") = #S_OK
        WorkBook = ExcelObject\GetObjectProperty("Workbooks\Add")
            If WorkBook
                ExcelObject\SetProperty("Cells(1,1) = 'Hello'")
                ExcelObject\SetProperty("Cells(1,2) = 'from'")
                ExcelObject\SetProperty("Cells(1,3) = 'COMate!'")
                Handle = ExcelObject\GetIntegerProperty("hWnd")
                
                Delay(3000)
                ExcelObject\SetProperty("Application\DisplayAlerts = #False")
                ExcelObject\Invoke("Quit()") 
                WorkBook\Release()
        EndIf
    EndIf
    
    Debug Handle
    If Handle
        ShowWindow_(Handle, #SW_RESTORE)
        MessageRequester("Handle", Str(Handle))
    EndIf

    ExcelObject\Release()
Else
    MessageRequester("COMate -Excel demo", "Couldn't create the application object!")
EndIf 
:!: But the window will not stay in the foreground as long as the PB program is active.
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: COMatePlus question

Post by captain_skank »

Code: Select all

LVAR_handle = ExcelObject\GetIntegerProperty("hWnd")
SetForegroundWindow_(LVAR_handle)
This does the trick nicely.
Marc56us - :!: But the window will not stay in the foreground as long as the PB program is active.
Yeah that's why i needed the above.

Thanks muchly for all the help
Post Reply