我一直在构建一个脚本来帮助我的工作流程,并且遇到了FIND和Excel的问题。我整理的代码工作了很短的时间,我不知道它发生了什么或为什么它不再工作。
我的问题是这个...我有一个excel的图像数据列表,如文件名和拍摄名称。我希望脚本扫描拍摄名称列并在文件名列中搜索匹配的名称,然后完全删除该行。重复该操作以继续,直到检查完所有行。
EX.
Filename Shoot Name
ABC DOS
DEF OXL
GHI DEF
JKL ASC
SO ..在这种情况下,应该删除整行DEF,因为它显示在拍摄名称列中。下面是我正在使用的代码,D列是我的拍摄名称,B列是我的文件名。
tell application "Microsoft Excel"
activate
repeat
set checkShootName to get value of cell ("D" & RowNo)
if checkShootName ≠ "" then
set ShootName to value of cell ("D" & RowNo) as string
set searchRange to range ("B:B")
set foundRange to find searchRange what ShootName
set fRow to first row index of foundRange
set myData to value of range ("B" & fRow as text)
delete entire row of cell ("B" & fRow)
set endCount to 0
else
set endCount to endCount + 1
if endCount > 100 then
exit repeat
end if
end if
set RowNo to RowNo + 1
end repeat
end tell
现在当我运行它时,脚本一直停留在"设置foundRange以找到searchRange什么ShootName"出现错误"错误" Microsoft Excel出错:参数错误。"数字-50"。
我比较新的代码,但如果有人能指出我正确的方向或建议更好的选择!
答案 0 :(得分:0)
我认为问题是“查找”找不到任何细胞。它会产生错误。您可以在try / end try块中处理它,如下所示:
try
set foundRange to find searchRange what Shootname
set fRow to first row index of foundRange
on error -- nothing found
set fRow to 0
end try
对于后续步骤,如果fRow不为0,则找到row并删除,如果fRow为0,则行未找到。