Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Excel error in Applescript

I have been using a script to compile data from monthly reports to an annual report. Recently one of the scripts has been returning a "file already open" warning. This only happens when I run the script for this location. I use similar scripts for different locations and they run fine. I don't know why this one suddenly quit working. I have tried copying and modifying the working scripts but get the same open file warning. I understand some of the script but not all of it. I had help putting it together and i'm hoping another set of eyes can help me out. The script opens the annual report and compiles the info from the other files, then saves the report and files the monthly reports in their respective month. Any suggestions would be greatly appreciated.


property total_student : 1

tell application "Finder"

set master_path to alias "users:fac:Desktop:Temple Annual Reports:DWI Annual Report:DWI Report.xlsx"


set filesWithDWI to get every file of folder ((path to desktop folder) & "Temple Annual Reports:DWI Annual Report" as string) whose name contains "DWI"



repeat with f in filesWithDWI

my transfer_data(f, master_path)

end repeat

end tell



on transfer_data(child_path, master_path)


tell application "Microsoft Excel"

set child_book to (open workbook workbook file name (child_path as string))

set child_doc to worksheet 1 of child_book


set master to worksheet "Sheet1" of (open workbook workbook file name (master_path as string))

set num to 14 --All lists start at index 12 or later, I'm putting 10 to be safe

set students to {}

tell child_doc --grab values from child document

repeat until (value of cell (("A" & num) as string)) is 1

set num to num + 1

end repeat

repeat until (value of cell (("B" & num) as string)) is ""

set end of students to {name:(value of cell (("B" & num) as string)), driver_id:(value of cell (("C" & num) as string)), DOB:(value of cell (("D" & num) as string)), pre_test:(value of cell (("J" & num) as string)), post_test:(value of cell (("K" & num) as string)), cert_id:(value of cell (("L" & num) as string)), NDP:(value of cell (("J" & num) as string))}

set num to num + 1


end repeat

set startdate to range "C6"

set classlocation to range "C10"

set instructor to range "I7"


end tell


tell master

set num to 7

log (value of cell (("B" & num) as string))

repeat until (value of cell (("B" & num) as string)) is ""


set num to num + 1

end repeat

repeat with student in students

set value of cell (("A" & num) as string) to total_student

set value of cell (("B" & num) as string) to name of student

set value of cell (("C" & num) as string) to driver_id of student

set value of cell (("D" & num) as string) to DOB of student

set value of cell (("E" & num) as string) to classlocation

set value of cell (("f" & num) as string) to startdate

set value of cell (("G" & num) as string) to instructor

set value of cell (("H" & num) as string) to pre_test of student

set value of cell (("I" & num) as string) to post_test of student

set value of cell (("J" & num) as string) to cert_id of student

set value of cell (("k" & num) as string) to NDP of student


set num to num + 1

set total_student to total_student + 1

end repeat


end tell

save child_book

close child_book

save active workbook in master_path

close active workbook

end tell


end transfer_data

do shell script "

for f in \"$HOME/Desktop/Temple Annual Reports/DWI Annual Report/\"*

do

if [ ! -d \"$f\" ]; then

x=\"${f%%.*}\"

i=$((${#x}-3))

if [ -d \"$HOME/Desktop/Temple Monthly Reports/DWI Monthly/${f:$i:3}\" ]; then

mv \"$f\" \"$HOME/Desktop/Temple Monthly Reports/DWI monthly/${f:$i:3}\"

fi

fi

done"

MacBook Pro (13-inch Mid 2012), OS X El Capitan (10.11.4)

Posted on Apr 24, 2016 8:33 PM

Reply
9 replies

Apr 26, 2016 9:23 AM in response to samiam2356

Looks like the xls file from the previous open was not saved and is still open.

Maybe it just needs a bit more time before opening file again.

Try adding a delay after close active workbook:


save child_book

close child_book

save active workbook in master_path

close active workbook

delay 10


If this works, you can reduce the 10 second delay to a shorter amount.

Apr 27, 2016 3:16 PM in response to Tony T1

I use this for different classes. The format is generally the same. The names of the cells may change but most of it is the same. I can modify the others to do what i want but this one hangs up. I've even tried copying a working script and excel files and modifying them but i get the same result.

User uploaded file



<Image Edited by Host to Remove Personal Information>

Apr 28, 2016 8:47 AM in response to Tony T1

I am working on that. In the meantime, I tried clicking on YES to see maybe it needed permisson to save the file. when i did, i got this error in the applescript result box: error "Microsoft Excel got an error: active workbook doesn’t understand the “save” message." number -1708 fromactive workbook. That was on this part of the script

save child_book

close child_book

save active workbook in master_path

close active workbook

Don't know if that sheds any light but thought id mention it while i work on the other.

Apr 28, 2016 8:56 AM in response to Tony T1

I ran the script on this portion:

property total_student : 1

tell application "Finder"

set master_path to alias "users:fac:Desktop:Temple Annual Reports:DWI Annual Report:DWI Report.xlsx"


set filesWithDWI to get every file of folder ((path to desktop folder) & "Temple Annual Reports:DWI Annual Report" as string) whose name contains "DWI"



repeat with f in filesWithDWI

my transfer_data(f, master_path)

end repeat

end tell



on transfer_data(child_path, master_path)


tell application "Microsoft Excel"

set child_book to (open workbook workbook file name (child_path as string))

set child_doc to worksheet 1 of child_book


set master to worksheet "Sheet1" of (open workbook workbook file name (master_path as string))

set num to 14 --All lists start at index 12 or later, I'm putting 10 to be safe

set students to {}

tell child_doc --grab values from child document

repeat until (value of cell (("A" & num) as string)) is 1

set num to num + 1

end repeat

repeat until (value of cell (("B" & num) as string)) is ""

set end of students to {name:(value of cell (("B" & num) as string)), driver_id:(value of cell (("C" & num) as string)), DOB:(value of cell (("D" & num) as string)), pre_test:(value of cell (("J" & num) as string)), post_test:(value of cell (("K" & num) as string)), cert_id:(value of cell (("L" & num) as string)), NDP:(value of cell (("J" & num) as string))}

set num to num + 1


end repeat

set startdate to range "C6"

set classlocation to range "C10"

set instructor to range "I7"


end tell


This part was highlighted. I noticed the master path was part of the error both times i ran it. Is there something wrong with it?

:

Excel error in Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.