Jump to content
Sign in to follow this  
Milkmannetje

[Excel] Can't close Excel when Screensaver is active...

Recommended Posts

Milkmannetje

Hi there!

This is a script to open an Excel document of the user's choice, and automatic refresh it every x minutes.

The refreshing is: Close the readonly Excel document, and directly reopen it. (A loop of course)

Just one little problem:

When the screensaver becomes active, it won't close excel anymore, but just opens another instance of the file. Resulting that when I end the screensaver, there are more then 10 instances of Excel active.

Can anyone help me with this annoying problem?

Opt("WinTitleMatchMode", 2)

Local $selectXLS = "Selecteer het gewenste Excel bestand."
Local $openXLS = FileOpenDialog($selectXLS, @ScriptDir & "\", "Excel bestanden (*.xls;*.xlsx)", 1)

If @error Then
MsgBox(4096, "", "Geen bestand gekozen.")
Exit
Else
$FileName = $openXLS
EndIf

if not FileExists($FileName) then
Msgbox (0,"Bestandsfout","Ik kan het bestand niet vinden. "& $FileName)
Exit

Else


Local $xLoop = 1
Local $tijdSec = InputBox("Tijdschema Opgeven", "Geef de verversingstijd van bestand in minuten: (bijv: 20)")
If @error = 1 Then
MsgBox(4096, "Sluiten", "Programma afgebroken.")
Exit
Else
; OK geklikt, nu openen bestand en verversingsloop in.
If $tijdSec < 1 Then
MsgBox(4096, "Sluiten", "De minimale verversingstijd is 1 minuut.")
Exit
Else
While $xLoop = 1
ShellExecute("excel.exe", '/r "' & $FileName & '"', @ScriptDir, "", @SW_MAXIMIZE)
Sleep($tijdSec*1000*60)
if ProcessExists("excel.exe") Then
WinWaitActive("Microsoft Excel")
WinClose("[ACTIVE]", "")
Else
Exit
EndIf
WEnd
EndIf
EndIf
EndIf

Share this post


Link to post
Share on other sites
BrewManNH

http://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F

Also, there's an Excel UDF that comes with AutoIt that would probably make this a whole lot easier to do. Or look for the rewrite of that UDF that water is doing that fixes a lot of issues the old one has.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

×