コマンドプロンプトから普通にやるとexcelでは起動できず、start excelでないと起動できない…Why?
だから:!start excel ファイル.xlsxするとE371: コマンドがありませんとエラー表示されてしまう。
!cmd /c start excel ファイル.xlsxとするば起動できるけど長すぎる…
let $PATH .= ';C:\Program Files (x86)\Microsoft Office\Office16'
command! -nargs=* Excel call s:LaunchExcel(<f-args>)
function! s:LaunchExcel (file)
let file = '"' . a:file . '"'
let command = '!Excel ' . file
execute command
endfunction
command! -nargs=* Word call s:LaunchWord(<f-args>)
function! s:LaunchWord (file)
let file = '"' . a:file . '"'
let command = '!WINWORD ' . file
execute command
endfunction
command! -nargs=* POWERPNT call s:LaunchPOWERPNT(<f-args>)
function! s:LaunchPOWERPNT (file)
let file = '"' . a:file . '"'
let command = '!POWERPNT ' . file
execute command
endfunction
とか考えたのだけど…コマンドプロンプトが立ち上がるのがウザい…
で調べると、どうも vim にstartというコマンドがあって、
Vimからアプリケーションをバックグラウンドで起動するいくつかの方法 - Humanityな情報を発見する。
なので!start ファイル.xlsxとすれば既定のアプリで開くことが出来る…上のようなファンクション要らない。知らなかった
あと、!start excelで新規Excelを起動をすることは出来る。引数付けると上記のように駄目だけど。
Excelだけでなく、特定のurlをブラウザを開くときも!start 特定のURLでよろしくやってくれる。