投稿‎ > ‎

ファイルを開く

posted Aug 20, 2018, 6:25 PM by Zhang Wenxu   [ updated Aug 20, 2018, 6:25 PM ]
Public Sub openme()
    Dim filename As String
    Dim fso As New FileSystemObject
    Dim sh As Object
   
    filename = ActiveCell.Value
   
    If fso.GetExtensionName(filename) = "xls" Or fso.GetExtensionName(filename) = "xlsx" Then
        Call Workbooks.Open(filename)
        Exit Sub
    End If
    If fso.GetExtensionName(filename) = "js" Then
        Shell "C:\Program Files (x86)\sakura\sakura.exe " & filename
        Exit Sub
    End If
    If fso.GetExtensionName(filename) = "xml" Then
        Shell "C:\Program Files (x86)\sakura\sakura.exe " & filename
        Exit Sub
    End If
    If fso.GetExtensionName(filename) = "bat" Then
        Shell "C:\Program Files (x86)\sakura\sakura.exe " & filename
        Exit Sub
    End If
   
    'Set sh = CreateObject("Shell.Application")
    'Call sh.Open(filename)
    Shell "explorer.exe " & filename
End Sub

Public Sub showInExplorer()
    Dim filename As String
    Dim fso As New FileSystemObject
    Dim sh As Object
   
    filename = ActiveCell.Value
    filename = "C:\workspace\" & Replace(filename, "/", "\")
    If fso.GetExtensionName(filename) = "xls" Or fso.GetExtensionName(filename) = "xlsx" Then
        Call Workbooks.Open(filename)
        Exit Sub
    End If
   
    Shell "explorer.exe /select," & filename, vbNormalFocus
End Sub
Comments