0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

クリップボードにコピーしたファイルパスやURLをショートカットキーで開く

Last updated at Posted at 2025-01-18
openFolderURL.vbs
Dim path, rawPath
Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("Wscript.Shell")

' クリップボードからパスを取得する
On Error Resume Next
rawPath = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")
On Error GoTo 0

If IsEmpty(rawPath) Or IsNull(rawPath) Then
    MsgBox "クリップボードの内容が文字列ではありません。"
Else
    ' クリップボードの内容がダブルクォーテーションで囲まれているか確認
    If Left(rawPath, 1) = """" And Right(rawPath, 1) = """" Then
        path = rawPath
        rawPath = Mid(rawPath, 2, Len(rawPath) - 2) ' ダブルクォーテーションを取り除く
    Else
        path = """" & rawPath & """"
    End If

    ' URLの場合はEdgeで開く
    If InStr(LCase(rawPath), "http://") > 0 Or InStr(LCase(rawPath), "https://") > 0 Then
        shell.Run "microsoft-edge:" & rawPath
        'shell.Run "chrome.exe " & rawPath  'chromeで開く場合
    Else
        ' ファイルパスとして有効かどうかをチェック
        If fso.FolderExists(rawPath) Or fso.FileExists(rawPath) Or Left(rawPath, 2) = "\\" Then
            ' 有効な場合はエクスプローラで開く
            shell.Run "explorer " & path
        Else
            MsgBox "無効なファイルパスです: " & rawPath
        End If
    End If
End If

(26行あたりURLを開くブラウザを変更)
Edge(デフォルト)

shell.Run "microsoft-edge:" & rawPath
Chrome
shell.Run "chrome.exe " & rawPath

ショートカットをデスクトップに作成してショートカットキーを割り当て

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?