Jump to content

Automatically Detect and Close Windows


Recommended Posts

Hello,

I am still new to AutoIT and relatively new to programming.

I've been trying to create a script that uses the native Excel.au3 to launch a spreadsheet..

The spreadsheet has hyperlinks to executables inside...

When you click a link to a .exe file in Excel you get an error window popping up warning you about viruses...

So what I want is to make my script that launches the Excel file:

1. Run constantly in the background until the Excel file is closed

2. Automatically detect the error window that pops up and select the OK button

I've been trying to use Yashied's WinAPIEx.au3 to accomplish this, but I am not just not smart enough. Perhaps there is any easier way?

Thanks guys for any hints advice etc.

Link to comment
Share on other sites

cdDan,

Welcome to the forums.

Why not just change the macro security level in Excel as that is what is causing your problem in the first place?

You can easily create a prog in AutoIT to close windows by title, even part of the title, but my first suggestion is all you need.

Regards,

4Eyes

Link to comment
Share on other sites

Sorry, here is the last code I tried:

#include "Excel.au3"

$path = @scriptdir & "\myfile.xlsx"

_ExcelBookOpen($path)

sleep(1000)

Global $excTitle = WinGetTitle("[active]")
Global $state = WinGetState("excTitle")

Do
$newwin = WinGetTitle("[active]")
If $newwin == "Microsoft Office" Then
    Send("{TAB}{SPACE}")
    sleep(20)
Else
    sleep(20)
EndIf
$state = WinGetState("excTitle")    
Until $state = 0
Link to comment
Share on other sites

cdDan,

Welcome to the forums.

Why not just change the macro security level in Excel as that is what is causing your problem in the first place?

You can easily create a prog in AutoIT to close windows by title, even part of the title, but my first suggestion is all you need.

Regards,

4Eyes

Hi, thank you for the welcome! Actually there are no macros in my spreadsheet. As a precaution I did disable macro security and add my file path to the "Trusted" areas, but it does not matter. It is a deeper issue with Microsoft Office which one M$ support article says you can disable through registry hacks. I have tried these hacks to no avail.

Link to comment
Share on other sites

cdDan,

Can you capture the error and post a pic here?

If you are intent on using AutoIT to close the windows check out the funcs WinClose() and WinKill() in the help file. Also, you can use ShellExecute() to launch the spreadsheet. It'll launch the appropriate program for whatever filetype you specify. Very handy.

I still think fixing the root problem is better. Can you change the hyperlinks to bat files that call the exe files? Try it and see.

4Eyes

Edited by 4Eyes
Link to comment
Share on other sites

I figured it out, case closed :idea:

Here is my final code:

#include "Excel.au3"

$path = @scriptdir & "\myfile.xlsx"

_ExcelBookOpen($path)

sleep(1000)

Global $excTitle = WinGetTitle("[active]")
Global $state = WinGetState("excTitle")

Do
If BitAnd($state, 0) Then
    $close = 1
Else
sleep(20)
If WinGetTitle("[active]") == "Microsoft Office" Then
    Send("{TAB}{SPACE}")
EndIf
$close = 0
EndIf
Until $close = 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...