2017-01-16 6 views
0

返されたテキストと返されたボタンの組み合わせによって、開いているExcelシートの特定のセルが変更されたスクリプトを作成しようとしています。基本的に1を加えたり、指定したセルの現在の値から1を引いたりします。以下のコードを使用して今動作するのは、ユーザーが -cancel-ボタンをクリックしたときだけです。「変更は行われませんでした」というダイアログが表示されます。これは予想通りです。AppleScriptを使用してExcelセル+1または-1の値を変更する方法

「12502525981」というテキストを入力して追加ボタンをクリックしてもエラーは発生しません。単に何も起こらない。

また、私はそれが私に期待する方法を凌駕するとは思わないと思います。

多くの感謝のExcelに組み込まれてVBAを使用しないのはなぜ

dialog picture enter image description here

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 
+0

? – Chrismas007

+0

組織内でマクロを使用することはできません。だから私は他のメソッド –

答えて

0
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" 
+0

に頼らざるを得ないので、ユーザーが入力しているUPCバーコードに1を追加しようとしているようです。私はセルC2にある数量に1を加えようとしています。 (私の理解は正しいのですか?) –

関連する問題