在Excel中查找和删除Applescript

我一直在build立一个脚本来帮助我的工作stream程,并且遇到了FIND和Excel的问题。 我放在一起的代码工作了很短的时间,我不知道它发生了什么事,或者为什么它不再工作。

我的问题是这样的…我有一个图像数据,如文件名和拍摄名称的Excel列表。 我正在寻找脚本通过拍摄名称列进行扫描,并search文件名列中的匹配名称,然后完全删除该行。 重复该操作继续,直到检查完所有行。

EX. Filename Shoot Name ABC DOS DEF OXL GHI DEF JKL ASC 

所以在这种情况下,整个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 

现在,当我运行它的脚本不断卡住“set foundRangefindsearch范围什么ShootName”与错误“错误”Microsoft Excel得到一个错误:参数错误。“数字-50”。

我更新的代码,但如果任何人都可以指出我正确的方向或build议的替代品将是伟大的!

我认为这个问题是当“查找”没有find任何单元格。 它会产生一个错误。 你可以在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,则find行并且可以将其删除,如果fRow为0,则找不到行。