访问:Shell cmd打开MDB [英] Access: Shell cmd Open MDB
本文介绍了访问:Shell cmd打开MDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用以下命令通过VBA打开另一个MDB Access文件:
I have been using the following command to open another MDB Access file via VBA:
Shell "cmd /c " & Chr(34) & strNewFullPath & Chr(34), vbHide
strNewFullPath是MDB文件的完整路径. 使用Access 2010时可以正常工作,但不能在Access 2003上运行. 如果我在XP DOS终端中运行该命令,它将运行.
strNewFullPath is the full path of the MDB file. Works fine when using Access 2010, but doesn't run on Access 2003. If I run the command in a XP DOS terminal it DOES run.
我还可以使用什么其他命令在Access 2003运行时在和上运行?
What other command can I use that should work on Access 2003 up and with the Access Runtime?
推荐答案
您可以使用Win32 API查找与文件类型关联的EXE名称,并将其像这样添加到您的shell命令中:
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
这篇关于访问:Shell cmd打开MDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文