2016-03-28 3 views
0

Я пытаюсь сохранить первый график в листе, называемом диаграммами, как PNG для рабочего стола. Я получаю следующую ошибку в строке «Сохранить как изображение»:Applescript/Excel Сохранение диаграмм как изображений

Ошибка «Microsoft Excel получил сообщение об ошибке« Ошибка параметра ». номер -50

tell application "Microsoft Excel" 
    set theChart to first chart object of sheet "Charts" 
    set filePath to "Macintosh HD:Users:User:Desktop:Chart.png" as text 
    save as picture theChart picture type save as PNG file file name filePath 
end tell 

Я также попытался рассказать саму диаграмму и получать ту же ошибку:

tell theChart 
    save as picture picture type save as PNG file file name filePath 
end tell 

Из словаря и других известных примеров синтаксис кажется правильным, но любая помощь будет в значительной степени оценили.

ответ

0

Microsoft Office 2016 очень строг для обеспечения безопасности при использовании скрипта.

  • Если файл уже существует, то номер ошибки -50.
  • если в этой папке нет файлов в списке последних файлов из Excel, то номер ошибки -50.

Решение, используйте:

set myFolder to path to desktop folder 
tell application "Microsoft Excel" 
    alias myFolder -- first, need this line to grant access to the folder before saving the PNG file , otherwise --> Parameter error. number -50 
    my deleteIfExists(myFolder, "Chart.png") -- second, if the file already exists, then delete the file, otherwise --> Parameter error. number -50 

    set theChart to first chart object of sheet "Charts" 
    save as picture theChart picture type save as PNG file file name ((myFolder as string) & "Chart.png") 
end tell 

on deleteIfExists(f, tName) -- move the file to the trash 
    tell application "Finder" to tell item tName of folder f to if exists then delete 
end deleteIfExists 
Смежные вопросы