ちょっと生きづらさを抱えた人へ、気持ちを楽にするためのお手紙です。

【VBA】ショートカットを作成する

参照設定 > Windows Script Host Object Model

 

'----------------------------------------------------------------
' 関 数 名:ショートカット作成
' 処理概要:ショートカットを作成する
' 引    数:src As String   ショートカットのリンク先パス
'          dst As String   作成するショートカットのパス
' 返 却 値:True 成功
'          False 失敗
'----------------------------------------------------------------
Function createShortcut(ByVal src As String, ByVal dst As String) As Boolean
    Dim objShell As New WshShell
    Dim objShortCut As WshShortcut
    
    On Error GoTo ERR_LBL
    
    Set objShortCut = objShell.createShortcut(dst)
    With objShortCut
        .TargetPath = src
        .Save
    End With
    createShortcut = True
    GoTo TERM_LBL
    
ERR_LBL:
    createShortcut = False
TERM_LBL:
    Set objShell = Nothing
    Set objShortCut = Nothing
End Function

参考
@IT
第14回 WshShellオブジェクトを利用する(3) (2/4)

コメントを残す

メールアドレスが公開されることはありません。

CAPTCHA