Sign in to follow this  
Followers 0
danusko

check if excel workbook is open

9 posts in this topic

#1 ·  Posted (edited)

Hi all,

please i use Autoit 3.0.100. I want use this vs.

Can i check with autoit, if is xls file open (is read-only) and if not, so overwrite this file with a new one.

Or need i the excel.au3 file wich is in INCLUDE folder?

thx

this doesnt work.

$file = FileOpen('"y:\1220\A\B\C\file.xls"', 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileCopy('"c:\1220\auto\cat\file.xls", "y:\1220\A\B\C\*.*"',1)
Edited by danusko

Share this post


Link to post
Share on other sites



Hi all,

please i use Autoit 3.0.100. I want use this vs.

Can i check with autoit, if is xls file open (is read-only) and if not, so overwrite this file with a new one.

Or need i the excel.au3 file wich is in INCLUDE folder?

thx

this doesnt work.

$file = FileOpen('"y:\1220\A\B\C\file.xls"', 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileCopy('"c:\1220\auto\cat\file.xls", "y:\1220\A\B\C\*.*"',1)
Before you try the copy, attempt to open the file for write (close it again without writing anything, of course). If the FileOpen() for write fails, you have your answer.

If you want to check specifically for Excel having the file open, then you could attempt _ExcelBookAttach() using the full file path, and if it fails then Excel does not have the file open.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

thank you very much

its works perfect :P

Share this post


Link to post
Share on other sites

thank you very much

its works perfect :P

sorry, one more question

if i want to check, if the file in destination folder exist and if YES, than copy the file with the same name + date in format DDMMYY

so if the name is "file", it will copy as file110309.xls

how can i do this?

thx a lot

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

sorry, one more question

if i want to check, if the file in destination folder exist and if YES, than copy the file with the same name + date in format DDMMYY

so if the name is "file", it will copy as file110309.xls

how can i do this?

thx a lot

Use the Date macros, though I suggest reformatting so the dates will automatically sort by _YYYYMMDD:
$sDestination = "file" & "_" & @YEAR & @MON & @MDAY & ".xls"

This example would be: file_20090311.xls

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Use the Date macros, though I suggest reformatting so the dates will automatically sort by _YYYYMMDD:
$sDestination = "file" & "_" & @YEAR & @MON & @MDAY & ".xls"

This example would be: file_20090311.xls

:mellow

i don know if i understund

i try this with using your advise..but doesnt works

[quote]#include "C:\Documents and Settings\aaa\docs\programs\autoit3\Include\date.au3"

$sDestination = "file" & "_" & @YEAR & @MON & @MDAY & ".xls"

$file = FileCopy("C:\P\a.xls", "C:\P\aa\*.*",0)
; FileCopy("C:\P\a.xls", "C:\P\aa\*.*",0)



If $file = 0 Then
    MsgBox(0, "ERROR", "Not good")
    Exit
EndIf
ToolTip("OK", 350, 200)
Sleep(3000)
Edited by danusko

Share this post


Link to post
Share on other sites

i´ve got it

it works good thx very much

Share this post


Link to post
Share on other sites

Opened Excel file have ~$filename.xlsx at the folder, check if the file not exist.

#include <file.au3>        

Local $ExcelFilePath = "D:\Data\Office\Excel\Accounts.xls"

Local $checkExcel = StringSplit($ExcelFilePath,"\"); split file path with delimiter of "\"
Local $tempExcel = $checkExcel[1]
        For $enumtemp = 2 to Ubound($checkExcel)-2
            $tempExcel = $tempExcel & "\" & $checkExcel[$enumtemp]
        Next

$tempExcel = $tempExcel & "\~$" & $checkExcel[Ubound($checkExcel)-1]; construct new filename of temporary file excel at the same specified directory, the file have prefix ~$ at the filename

While FileExists($tempExcel); check if the temporary file exist, delay here as long as the temporary file exist
        Sleep(10000)
WEnd

;Do what you want to do with excel file, it's free now

Share this post


Link to post
Share on other sites

Welcome to AutoIt and the forum!

You posted to a 5 years old thread. Do you think anyone is still interested in a solution ;)

Please do not necro old posts.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  
Followers 0