Jump to content
Sign in to follow this  
cdDan

Automatically Detect and Close Windows

Recommended Posts

cdDan

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.

Share this post


Link to post
Share on other sites
4Eyes

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

Share this post


Link to post
Share on other sites
cdDan

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

Share this post


Link to post
Share on other sites
cdDan

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.

Share this post


Link to post
Share on other sites
4Eyes

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

Share this post


Link to post
Share on other sites
cdDan

Certainly, here it is.

post-57801-12738880867761_thumb.jpg

Share this post


Link to post
Share on other sites
cdDan

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

Share this post


Link to post
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
Sign in to follow this  

×