Applescript 从excel回显值中写入数据,然后递增

Applescript 从excel回显值中写入数据,然后递增,applescript,Applescript,我只是想制作一个apple脚本,从excel电子表格单元格B2读取数据,并将var1设置为B2的值,但我希望它检查单元格A2,确定系统所在的时间与A2的值匹配,如果匹配,则取B2的值并将其设为变量 这将是第一次,也是第二次从A3和B3收集数据 set SystemTime to (current date) set current_row to 2 #Set starting row repeat tell application "Microsoft Excel"

我只是想制作一个apple脚本,从excel电子表格单元格B2读取数据,并将var1设置为B2的值,但我希望它检查单元格A2,确定系统所在的时间与A2的值匹配,如果匹配,则取B2的值并将其设为变量

这将是第一次,也是第二次从A3和B3收集数据

   set SystemTime to (current date)

   set current_row to 2 #Set starting row
   repeat
tell application "Microsoft Excel"
    set a_cell to (get value of cell (("A" & current_row) as string)) #Get A cell val
    if a_cell = SystemTime then #If times match up
        set b_cell to (value of cell (("B" & current_row) as string)) #Get B         cell val
        display dialog b_cell #Display that val
        current_row = current_row + 1 #Increment the row we're looking at

    end if
  end tell
end repeat

您的单元格名称必须是字符串(用引号括起来),并且需要将它们转换为单元格对象(即
单元格“A2”
)。我不知道你问脚本第二次从
A3
B3
收集数据时是什么意思,它什么时候会这样做?在其他地方?如果不是,如果
A2
与系统时间不匹配,您希望发生什么?到目前为止,我让它等待两分钟,然后再试一次…请更清楚地了解你在寻找什么

repeat
    tell application "Microsoft Excel"
        set a2 to (get value of cell "A2") 
        if a2 = SystemTime 
            set var to (Value of cell "B2")
            display dialog var
            exit repeat
        else
            delay 120 #wait 2 minutes
        end if
    end tell
end repeat
编辑:

好的,在您的评论之后(假设您希望检查之间的等待时间为2分钟):


假设我在a2中有一个项目列表,b2 a2包含一个时间,比如说“1800”,b2包含一个字符串,比如说“test”,所以在系统时间“1800”时,它会将var设置为b2的值,这将是“test”,但第二轮它将从a3收集数据,a3将有时间2000,b3将有值“test2”所以一旦完成了a2,它就会转到a3,因为a2已经被使用了。@Josh Fisher先生,我明白了。脚本应多久检查一次?脚本应每2小时检查一次文件,是否可以给脚本一个链接以打开工作簿进行检查,而不是让microsoft excel在脚本运行时一直打开?请参阅编辑时间太精确,它显示秒数,会混淆脚本并错过执行的机会,它需要简化为20:00而不是20:00:13。您可能不希望相同的脚本循环并连续运行数小时。你可以制作一个闹钟,当它每两小时响一次时,让它运行Applescript,这将大大简化事情。
set current_row to 2 #Set starting row
repeat
    tell application "Microsoft Excel"
        set a_cell to (get value of cell (("A" & current_row) as string)) #Get A cell val
        if a_cell = SystemTime then #If times match up
            set b_cell to (value of cell (("B" & current_row) as string)) #Get B cell val
            display dialog var #Display that val
            current_row = current_row + 1 #Increment the row we're looking at
        else
            delay 120 #wait 2 minutes
        end if
    end tell
end repeat