2012-07-18 1 views
0

약 400 개의 Excel 파일이 있습니다. 기존 파일의 첫 번째 열 바로 앞에 열을 삽입 한 다음 해당 열의 각 행에 파일 이름을 삽입하고 싶습니다.Snow Leopard에서 Microsoft Excel과 상호 작용하는 AppleScript 코드 - 누락 된 기능을 추가하는 방법

저는 AppleScript를 약간 알고 있으며이 스크립트를 작성하여 스크립트에 일부 파일을 놓을 수있게하고 스크립트를 실행합니다.

누군가 "TO DO"라인을 완성하는 데 나를 도울 수 있는지 궁금합니다. 실행시이 스크립트는 내가 맨 위에 놓은 파일 경로가있는 대화 상자를 제공합니다. 그러나 Excel 응용 프로그램에서 "Not enough memory"라는 오류 대화 상자가 표시됩니다. 나는 단지 2 엑셀 파일로 이것을 시도했기 때문에 오류를 일으킨 파일의 수가 아니었다.

누군가 나를 TODO 줄을 작성하는 데 도움이 될 수 있습니까? 감사합니다

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 

덕분에 나는 모든 것을 이해하지 못하는 많은

답변

1

-> 해당 열의 각 행에 파일의 이름을 삽입 | TO각 열 각 파일의 이름에 텍스트를 삽입하십시오. 여기

는 스크립트, 업데이트 :

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)를 tell block application에 입력하십시오.

사용 이처럼 내 : 또한 set x to my addFilePath(eachFile)

에서, application Finder 블록에서 tell application "Microsoft Excel" 블록은 사용하지 않는 것이 좋습니다,이 예기치 않은 오류가 발생할 수 있습니다.

+1

귀하의 의견에 따라 답변을 업데이트했지만 삭제되었습니다. – jackjr300

+0

감사합니다. 나는 여전히이 스크립트를 쓰려고합니다. 당신의 해결책은 제가 지침으로 사용하는 것입니다. 나는 당신의 ans을 받아 들일 것이고, 또한 나의 해결책을 게시 할 것입니다. – banditKing

+0

안녕하세요. 그것은 아름답게 일했다 :) – banditKing

관련 문제