Search code examples
excelmacosapplescriptexcel-2008

Can't get the find command in Excel 2008 to work


I want to use AppleScript to find a TAG cell I put next to sets of data, so that I can then link to those values on a separate results sheet.

At the moment all I get is errors telling me that this, that and the other doesn't understand find. Here's the script:

tell application "Microsoft Excel"
    tell active workbook
        activate object worksheet "1001"
        tell sheet "1001"
            set searchRange to used range
            tell searchRange
                (find searchRange what "TAG")
            end tell
        end tell
    end tell
end tell

I'm a complete beginner with this so completely stumped


Solution

  • The following works very well for me: (this code goes between tell sheet "1001" and end tell):

    set searchRange to used range
    try
        set foundRange to find searchRange what "blurp" with match case
        (* do something with the foundRange *)
    on error -- not found
        (* do error handling *)
    end try
    

    If it finds "blurp", a range is returned (something like range "'[Workbook1]1001'!$D$4" of application "Microsoft Excel"), otherwise an error is thrown (which simply means that what you searched for was not found).