How to Test if an Excel File open in a script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Mabel
Posts: 6
Joined: 03 Jul 2018, 04:39

How to Test if an Excel File open in a script

12 Jul 2018, 15:19

How can I check if the Excel file is open for editing from a script?

I have a script that runs a PowerPoint presentation.

Powerpoint at some point in the script opens, and updates the links in it (the source data is an Excel Spreadsheet)

Now if the source Excel file is open for editing by someone then PowerPoint can’t update the links and the script gets confused.

How can I check if the Excel file is open from the script and thus make the script to tell Powerpoint not to update?

Thanks

Mabel
colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Re: How to Test if an Excel File open in a script

12 Jul 2018, 15:49

Do a fileMove on the excel file. If errorlevel is > 0 then you could assume that it failed because it is open.
Mabel
Posts: 6
Joined: 03 Jul 2018, 04:39

Re: How to Test if an Excel File open in a script

13 Jul 2018, 01:35

thank you

i will give that a go
Mabel
Posts: 6
Joined: 03 Jul 2018, 04:39

Re: How to Test if an Excel File open in a script

13 Jul 2018, 10:17

thanks that works.

pity there wasn't a is file open function.

thanks again
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: How to Test if an Excel File open in a script

13 Jul 2018, 12:54

Code: Select all

IsFileInUse(FileName) {
	return FileExist(FileName) && !FileOpen(FileName, "rw")
}
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: How to Test if an Excel File open in a script

13 Jul 2018, 13:36

slightly clunky excel com object approach...

Code: Select all

wb := A_Desktop "\Book1.xlsx"

if ( IsWorkbookOpen( wb ) = true )
{
	msgbox workbook is open!
	return	
}

IsWorkbookOpen( wb )
{
	xlObj 		:= ComObjCreate( "Excel.Application" ), xlObj.WorkBooks.Open( wb )
	ReadOnly 	:= xlObj.ActiveWorkbook.ReadOnly, xlObj.Quit
	return !ReadOnly ? 0 : 1
}
folded
tested/works here..;)
Mabel
Posts: 6
Joined: 03 Jul 2018, 04:39

Re: How to Test if an Excel File open in a script

16 Jul 2018, 00:33

thank you.

I was searching for things like file open and other things with open in the title.

i didn't think about using the "use"

silly me.

i will follow through on the way the function works. thanks

still at the start of the learning curve.

thanks for the help

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Joey5, matt101, Thorlian and 167 guests