Microsoft Excel

com.microsoft.officeでのVBの使用停止設定


サンプルコード

サンプルソース(参考)
行番号ソース
001<key>VBAObjectModelIsTrusted</key>
002<false />
003<key>AllowVisualBasicToBindToSystem</key>
004<false />
005
006<key>DisableVisualBasicExternalDylibs</key>
007<true />
008<key>DisableVisualBasicMacScript</key>
009<true />
010<key>DisableVisualBasicToBindToPopen</key>
011<true />
012<key>VisualBasicEntirelyDisabled</key>
013<true />
014<key>SendAllTelemetryEnabled</key>
015<false />
016
017<key>PayloadDisplayName</key>
018<string>Microsoft Office</string>
019<key>PayloadType</key>
020<string>com.microsoft.office</string>
AppleScriptで生成しました

|

[Excel]祭日入りカレンダー生成

Screencapture-20230610-130744

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

####設定項目
set numFontSize to 14 as number
##set strFontName to "Osaka−等幅" as text
##set strFontName to "Arial Unicode MS" as text
set strFontName to "メイリオ" as text


########################
#####ここから処理
####日付情報の取得--> 今の『年』の数値を求める
set ocidDate to refMe's NSDate's |date|()
set ocidCalendar to refMe's NSCalendar's autoupdatingCurrentCalendar()
set ocidCalendarUnitYear to refMe's NSCalendarUnitYear
set ocidCalendarUnitMonth to refMe's NSCalendarUnitMonth
set ocidDateComponents to ocidCalendar's components:((ocidCalendarUnitYear) + (ocidCalendarUnitMonth)) fromDate:ocidDate
set numSetYear to (ocidDateComponents's |year|) as integer
set numSetMonth to (ocidDateComponents's |month|) as integer
#####各種リスト
set listWeekDay to {"日", "月", "火", "水", "木", "金", "土"} as list
set listYear to {(numSetYear - 1), (numSetYear), (numSetYear + 1)} as list
set listMonth to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} as list
########################
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#####年ダイアログを出す
try
  set objResponseYear to (choose from list listYear with title "年選択" with prompt "年を選択してください" default items (item 2 of listYear) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
  log "エラーしました"
return
end try
if objResponseYear is false then
return
end if
set numSetYear to (objResponseYear) as integer
########################
#####月ダイアログを出す
if numSetMonth = 12 then
  set numSetMonth to 1 as integer
else
  set numSetMonth to numSetMonth + 1 as integer
end if
try
  set objResponseMonth to (choose from list listMonth with title "月選択" with prompt "月を選択してください" default items (item (numSetMonth) of listMonth) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
  log "エラーしました"
return
end try
if objResponseMonth is false then
return
end if
set numSetMonth to (objResponseMonth) as integer



########################
tell application "Microsoft Excel" to launch
###エクセルの基本処理
set strMonthNoZeroSupp to (text -2 through -1 of ("00" & numSetMonth)) as text
set strSheetName to ("" & numSetYear & "-" & strMonthNoZeroSupp & "") as text
set strFileName to ("" & strSheetName & "カレンダーxlsx") as text
set strDesktopPath to POSIX path of (path to desktop folder from user domain) as text
set strSaveFilePath to (strDesktopPath & strFileName) as text
####新規ワークブック
tell application "Microsoft Excel"
  activate
  set objWorkBook to make new workbook with properties {excel 8 compatibility mode:false}
  tell objWorkBook
    set strWorkBookName to name as text
  end tell
end tell
####シートの名前の変更
tell application "Microsoft Excel"
  tell objWorkBook
    tell active sheet
      set name to strSheetName
    end tell
  end tell
end tell
###A1 左上のセルの処理
tell application "Microsoft Excel"
  tell objWorkBook
    tell sheet strSheetName
      tell cell "A1"
set number format to "@"
###Aに年月を入力
set value to ("" & (numSetYear as text) & "/" & strMonthNoZeroSupp) as text
####タイトル行の処理
tell cell "$1:$1"
tell font object
set font size to numFontSize
set name to strFontName
set color to {0, 0, 0}
end tell
tell interior object
set color to {255, 255, 255}
end tell
tell border id border top
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border bottom
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border left
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border right
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
end tell
      end tell
    end tell
  end tell
end tell
########################
#####カレンダー初期化
set ocidCalendar to refMe's NSCalendar's calendarWithIdentifier:(refMe's NSCalendarIdentifierGregorian)
set ocidLocale to refMe's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP")
ocidCalendar's setLocale:(ocidLocale)
#####日付コンポーネント初期化
set ocidDateComponents to refMe's NSDateComponents's alloc()'s init()
ocidDateComponents's setYear:(numSetYear)
ocidDateComponents's setMonth:(numSetMonth)
set ocidDate to ocidCalendar's dateFromComponents:(ocidDateComponents)
###指定月のカレンダーの最大日数-->繰り返し回数になる
set ocidMonthDateRange to ocidCalendar's rangeOfUnit:(refMe's NSCalendarUnitDay) inUnit:(refMe's NSCalendarUnitMonth) forDate:(ocidDate)
set numDateLength to ocidMonthDateRange's |length|


########################
###祭日データJSONで取得
set strURL to "https://holidays-jp.github.io/api/v1/date.json" as text
set ocidJsonURL to refMe's NSURL's URLWithString:(strURL)
set ocidOption to refMe's NSDataReadingMappedIfSafe
set listDownLoadData to refMe's NSData's dataWithContentsOfURL:(ocidJsonURL) options:(ocidOption) |error|:(reference)
set ocidJsonData to (item 1 of listDownLoadData)
#####################
###JSON初期化 してレコードに格納
set listJSONSerialization to (refMe's NSJSONSerialization's JSONObjectWithData:(ocidJsonData) options:0 |error|:(reference))
set ocidJsonData to item 1 of listJSONSerialization
set ocidHolidayDict to refMe's NSDictionary's alloc()'s initWithDictionary:(ocidJsonData)

#####################
###取得するカレンダーの月(処理としては不要なんだけど、今後の展開のために処理)
set numYear to ocidCalendar's component:(refMe's NSCalendarUnitYear) fromDate:(ocidDate)
set numMonth to ocidCalendar's component:(refMe's NSCalendarUnitMonth) fromDate:(ocidDate)
###年はそのまま
set strYear to numYear as text
###月はゼロパディング
set strMonth to (text -2 through -1 of ("00" & (numMonth as text))) as text
###日付毎処理
set numCntRows to 2

repeat with numDayNo from (1) to (numDateLength)
  -->ここまでは年と月でのカレンダーなので
  ###日付を入れて
(ocidDateComponents's setDay:(numDayNo))
  set ocidDate to (ocidCalendar's dateFromComponents:(ocidDateComponents))
  set ocidWeekDayClender to (ocidCalendar's components:(refMe's NSWeekdayCalendarUnit) fromDate:(ocidDate))
  ###日付
  log ocidDate as date
  ###日付番号
  log numDayNo
  set strDayNoZeroSupp to (text -2 through -1 of ("00" & numDayNo)) as text
  #####################
  ###曜日処理
  set numWeekDayNo to (ocidWeekDayClender's |weekday|)'s intValue()
  ###曜日番号
  log numWeekDayNo
  ###曜日テキスト
  set strWeekDayJp to (item numWeekDayNo of listWeekDay) as text
  ###祭日取得用
  set strDateText to ("" & strYear & "-" & strMonth & "-" & strDayNoZeroSupp & "") as text
  ###祭日取得
  set ocidHolidayValue to (ocidHolidayDict's valueForKey:(strDateText))
  ###祭日処理
  if ocidHolidayValue is (missing value) then
    set numChkHoliday to 0 as integer
  else
    set numChkHoliday to 1 as integer
    set strHolidayValue to ocidHolidayValue as text
    log strHolidayValue
    ####Cの列
    set strCellNoHoliday to ("C" & numCntRows & "") as text
    tell application "Microsoft Excel"
      tell objWorkBook
tell sheet strSheetName
tell cell strCellNoHoliday
###Cの列に祭日名を入力
set value to (strHolidayValue)
end tell
end tell
      end tell
    end tell
  end if
  
  ###セル番号
  set strCellNoDay to ("A" & numCntRows & "") as text
  set strCellNoWeek to ("B" & numCntRows & "") as text
  set strCellRowsRange to "$" & numCntRows & ":$" & numCntRows & ""
  
  ########################
  ###エクセル処理
  tell application "Microsoft Excel"
    tell objWorkBook
      tell sheet strSheetName
tell cell strCellNoWeek
set value to strWeekDayJp
end tell
tell cell strCellNoDay
set value to strDayNoZeroSupp
end tell
      end tell
    end tell
    #######行処理
    tell cell strCellRowsRange
      set number format to "@"
      #####
      tell interior object
if numWeekDayNo = 1 then
set color to {254, 188, 190}
else if numWeekDayNo = 7 then
set color to {212, 243, 255}
else if numChkHoliday = 1 then
set color to {254, 188, 190}
else
set color to {255, 255, 255}
end if
      end tell
      #####
      tell font object
set font size to numFontSize
set name to strFontName
if numWeekDayNo = 1 then
set color to {170, 0, 0}
else if numWeekDayNo = 7 then
set color to {0, 88, 176}
else if numChkHoliday = 1 then
set color to {170, 0, 0}
else
set color to {0, 0, 0}
end if
      end tell
      tell border id border top
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
      tell border id border bottom
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
      tell border id border left
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
      tell border id border right
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
    end tell
  end tell
  
  set numCntRows to numCntRows + 1
end repeat

|

[Excel]行番号を入れる(パディング)

Screencapture-20230519-131838

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

set strZeroSup to "000" as text

set numMaxRow to 200 as integer

###起動
tell application "Microsoft Excel"
  launch
end tell
####起動待ち最大20秒
repeat 20 times
  tell application "Microsoft Excel"
    activate
    set boolFrontMost to frontmost as boolean
  end tell
  if boolFrontMost is true then
    exit repeat
  end if
  delay 1
end repeat

####ワークブック開いているか?チェック
tell application "Microsoft Excel"
  set refAcvWorkBook to active workbook
  if refAcvWorkBook is (missing value) then
return "ワークブックを開いていません"
  end if
end tell
##################################
###本処理
##################################
set numLineNo to 1 as integer
repeat (numMaxRow + 1) times
  if numLineNo = 1 then
    ####シートの名前の変更
    tell application "Microsoft Excel"
tell active workbook
tell active sheet
tell cell "A1"
###A1に斜線を入れる
tell border id diagonal down
set color to {0, 0, 0}
set line style to continuous
set weight to border weight thin
end tell
end tell
end tell
end tell
    end tell
  else
    ###項番ゼロパディング
    set strCellValue to (text -3 through -1 of (strZeroSup & (numLineNo - 1)) as text) as text
    ###セル番号整形
    set strCellNo to ("A" & (numLineNo as text)) as text
    tell application "Microsoft Excel"
tell active workbook
tell active sheet
tell cell strCellNo
##表示形式をテキストにして
set number format local to "@"
set number format to "@"
##あたいを入れる
set value to strCellValue
end tell
end tell
end tell
    end tell
  end if
  set numLineNo to numLineNo + 1 as integer
end repeat




|

[Excel]シートの使用中エリア全部でHTMLファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###シートの使用中エリア全部をコピー
##########################################
tell application "Microsoft Excel"
  tell active sheet
    tell used range
set rangeArea to areas
    end tell
  end tell
end tell
if rangeArea is (missing value) then
return "取得に失敗しました"
end if
tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidPublicHTML to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeHTML)
if ocidPublicHTML is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "html"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
ocidPublicHTML's writeToURL:(ocidFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)


tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]シートの使用中エリア全部でPNGファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###シートの使用中エリア全部をコピー
##########################################
tell application "Microsoft Excel"
  tell active sheet
    tell used range
set rangeArea to areas
    end tell
  end tell
end tell

if rangeArea is (missing value) then
return "取得に失敗しました"
end if

tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePNG)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "png"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]シートの使用中エリア全部でPDFファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###シートの使用中エリア全部をコピー
##########################################
tell application "Microsoft Excel"
  tell active sheet
    tell used range
set rangeArea to areas
    end tell
  end tell
end tell
if rangeArea is (missing value) then
return "取得に失敗しました"
end if
tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePDF)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "pdf"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]選択範囲のRangeの取得

【スクリプトエディタで開く】|

tell application "Microsoft Excel"
  tell selection
    set cellSelection to get address local
  end tell
  tell active sheet
    tell cell cellSelection
set rangeArea to areas
    end tell
  end tell
end tell
#####ログは以下のようになります
tell application "Microsoft Excel"
  get address local selection
    --> "$A$1:$F$12"
  get areas of cell "$A$1:$F$12" of active sheet
    --> {range "[Book1]Sheet1!$A$1:$F$12"}
end tell
結果:
{range "[Book1]Sheet1!$A$1:$F$12" of application "Microsoft Excel"}

|

[Excel]選択範囲でPNGファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###選択範囲をコピー
##########################################
tell application "Microsoft Excel"
  tell selection
    set cellSelection to get address local
  end tell
  tell active sheet
    tell cell cellSelection
set rangeArea to areas
    end tell
  end tell
end tell

if rangeArea is (missing value) then
return "取得に失敗しました"
end if

tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePNG)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "png"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]選択範囲でPDFファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###選択範囲をコピー
##########################################
tell application "Microsoft Excel"
  tell selection
    set cellSelection to get address local
  end tell
  tell active sheet
    tell cell cellSelection
set rangeArea to areas
    end tell
  end tell
end tell
if rangeArea is (missing value) then
return "取得に失敗しました"
end if
tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePDF)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "pdf"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]選択範囲でHTMLファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###選択範囲をコピー
##########################################
tell application "Microsoft Excel"
  tell selection
    set cellSelection to get address local
  end tell
  tell active sheet
    tell cell cellSelection
set rangeArea to areas
    end tell
  end tell
end tell
if rangeArea is (missing value) then
return "取得に失敗しました"
end if
tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidPublicHTML to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeHTML)
if ocidPublicHTML is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "html"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
ocidPublicHTML's writeToURL:(ocidFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)


tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom