如何更改excel单元格的值+;1或-1使用AppleScript

如何更改excel单元格的值+;1或-1使用AppleScript,excel,shell,automation,applescript,Excel,Shell,Automation,Applescript,我正在尝试编写一个脚本,其中返回的文本和返回的按钮组合会导致对打开的excel工作表中的特定单元格进行更改。基本上,将指定单元格的当前值加1或减1。现在使用下面的代码唯一有效的方法是当用户单击 -取消-按钮我得到对话框“未做任何更改”。这是预期的 当我输入文本“12502525981”并单击添加按钮时,我没有收到任何错误。只是什么都没发生 此外,我认为我没有按照excel+1期望的方式告诉它 非常感谢 为什么不使用Excel内置的VBA?我的组织中不允许使用宏。因此,我不得不求助于其他方法。

我正在尝试编写一个脚本,其中返回的文本和返回的按钮组合会导致对打开的excel工作表中的特定单元格进行更改。基本上,将指定单元格的当前值加1或减1。现在使用下面的代码唯一有效的方法是当用户单击 -取消-按钮我得到对话框“未做任何更改”。这是预期的

当我输入文本“12502525981”并单击添加按钮时,我没有收到任何错误。只是什么都没发生

此外,我认为我没有按照excel+1期望的方式告诉它

非常感谢


为什么不使用Excel内置的VBA?我的组织中不允许使用宏。因此,我不得不求助于其他方法。使用这种方法,看起来您试图在用户输入的UPC条形码中添加1。我试图在单元格C2中的数量上加1。(我的理解正确吗?)
try
set upcItem1 to "12502525981"
set upcItem2 to "12502600695"
set upcItem3 to "12502612346"

set the_Response to {text returned, button returned} of (display dialog "Enter the UPC of the item below..." buttons {"Add +1 ", "-Cancel-", "Remove -1"} default answer "")
item 1 of the_Response -- the text
item 2 of the_Response -- the button pressed

if item 2 of the_Response is equal to "Add +1" & item 1 of the_Response contains upcItem1 then
    tell application "Microsoft Excel"
        set value of cell "C2" to current value +1
    end tell

else if item 2 of the_Response is equal to "Remove -1" & item 1 of the_Response contains upcItem1 then
    tell application "Microsoft Excel"
        set value of cell "C2" to current value -1
    end tell

else if item 2 of the_Response is equal to "-Cancel-" then
    display notification "No change was made."
end if
on error
display notification "There was a problem with the UPC entered, try again or check the cell that it relates to."
end try
    set x to display dialog "Enter the UPC of the item below..." default answer "" buttons {"Add +1", "-Cancel-", "Remove -1"} default button 2
set {runButton, textButton} to {button returned of x, text returned of x}

if runButton is "Add +1" then
    try
        set myValue to (textButton + 1)
    on error
        display dialog "There was a problem with the UPC entered, try again or check the cell that it relates to."
        return
    end try

else if runButton is "Remove -1" then
    try
        set myValue to (textButton - 1)
    on error
        display dialog "There was a problem with the UPC entered, try again or check the cell that it relates to."
        return
    end try

else if runButton is "-Cancel-" then
    display dialog "No change was made."
    return
end if

tell application "Microsoft Excel"
    tell active sheet
        set value of cell "C2" to myValue
    end tell
end tell

display dialog "Done"