下面是一些在雪豹上与Microsoft Excel交互的Applescript代码-如何添加缺少的函数

下面是一些在雪豹上与Microsoft Excel交互的Applescript代码-如何添加缺少的函数,excel,applescript,osx-snow-leopard,automator,Excel,Applescript,Osx Snow Leopard,Automator,我有大约400个excel文件。我想在现有文件的第一列之前插入一列,然后将文件名插入该列的每一行 我知道一点Applescript,基于此,我编写了这个脚本,这样我可以将一些文件放到脚本中,它将在每个文件上执行脚本 我想知道是否有人能帮我完成“待办事项”一行。在执行时,这个脚本会给我对话框,上面有我放在上面的文件路径。但是excel应用程序抛出一个错误对话框,上面写着“内存不足”。我只使用了2个excel文件进行了尝试,因此导致错误的不是文件的数量 有没有人能帮我完成待办事项,并给我一个ide,

我有大约400个excel文件。我想在现有文件的第一列之前插入一列,然后将文件名插入该列的每一行

我知道一点Applescript,基于此,我编写了这个脚本,这样我可以将一些文件放到脚本中,它将在每个文件上执行脚本

我想知道是否有人能帮我完成“待办事项”一行。在执行时,这个脚本会给我对话框,上面有我放在上面的文件路径。但是excel应用程序抛出一个错误对话框,上面写着“内存不足”。我只使用了2个excel文件进行了尝试,因此导致错误的不是文件的数量

有没有人能帮我完成待办事项,并给我一个ide,说明我为什么会出错。谢谢

property numFiles : 0

on open excelFiles


set fileNames to ""

tell application "Finder"
    repeat with eachFile in excelFiles

        --open document file eachFile

        --tell application "Microsoft Excel"

        --increment count



        --save name of each file

        set fileNames to fileNames & return & (POSIX path of eachFile)

        --TO DO insert a column

        --TO DO insert text in each column to the name of eachFile

        --end tell
    end repeat
    display dialog fileNames
    --display dialog "Ouch that hurt " & return & "You dropped " & (count excelFiles) & "files on me"
end tell
end open

on addFilePath(eachFile)
set fileNames to fileNames & (POSIX path of eachFile)
end addFilePath

非常感谢

我什么都不懂-->将文件名插入该列的每一行|要做的事每一列中插入文本到每个文件的名称

以下是脚本,已更新:

    on open excelFiles
    set numFiles to count excelFiles
    repeat with eachFile in excelFiles -- open each file in Excel
        tell application "Microsoft Excel"
            set tBook to open workbook workbook file name (eachFile as string)
            set tName to name of tBook
            insert into range column 1 of active sheet -- insert column

            set lastCell to last cell of used range of active sheet -- get last cell from the used range
            set value of range ("A1:A" & first row index of lastCell) of active sheet to tName --set first column's values to the file name

            close tBook saving yes
        end tell
    end repeat
    display dialog numFiles
end open
编辑:我忘记了错误:

内存不足:这个奇怪的错误似乎是:在
告诉块应用程序中调用处理程序时未使用
my
tell me to

像这样使用my将x设置为my addFilePath(每个文件)


另外,不建议在
应用程序查找程序
块中使用
告诉应用程序“Microsoft Excel”
块,这可能会导致意外错误。

我根据您的评论更新了我的答案,但它已被删除。谢谢。我还在努力写这个脚本。你的解决方案就是我用来指导的。我会接受你的ans,然后发布我的解决方案