Jump to content

check if excel workbook is open


Recommended Posts

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
Link to comment
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
Link to comment
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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 5 years later...

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...