Access: Shell cmd Open MDB

前端 未结 6 1150
野趣味
野趣味 2021-01-21 03:38

I have been using the following command to open another MDB Access file via VBA:

Shell \"cmd /c \" & Chr(34) & strNewFullPath & Chr(34), vbHide
         


        
6条回答
  •  终归单人心
    2021-01-21 04:08

    You can use the Win32 API to find the EXE name associated with the file type and prepend it to your shell command like this:

    Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
    
    Public Function GetExecutableForFile(strFileName As String) As String
       Dim lngRetval As Long
       Dim strExecName As String * 255
       lngRetval = FindExecutable(strFileName, vbNullString, strExecName)
       GetExecutableForFile = Left$(strExecName, InStr(strExecName, Chr$(0)) - 1)
    End Function
    
    Sub RunIt(strNewFullPath As String)        
       Dim exeName As String
    
       exeName = GetExecutableForFile(strNewFullPath)         
       Shell exeName & " " & Chr(34) & strNewFullPath & Chr(34), vbNormalFocus
    End Sub
    

提交回复
热议问题