我想通了。這是我使用的代碼。 (請注意,我改變了Access數據庫文件。
If Not Len(Dir("C:\Program Files\Microsoft Office\Office12\msaccess.exe", vbDirectory)) = 0 Then
Call Shell(Chr$(34) & "C:\Program Files\Microsoft Office\Office12\msaccess.exe" & Chr$(34) & " " & Chr$(34) & "http://stoneplastics/Departments/Quality/Databases/ItemInspectionInstructionPrintOutRev3.accdb" & Chr$(34) & " /runtime", vbMaximizedFocus)
End If
If Not Len(Dir("C:\Program Files\Microsoft Office\Office14\msaccess.exe", vbDirectory)) = 0 Then
Call Shell(Chr$(34) & "C:\Program Files\Microsoft Office\Office14\msaccess.exe" & Chr$(34) & " " & Chr$(34) & "http://stoneplastics/Departments/Quality/Databases/ItemInspectionInstructionPrintOutRev3.accdb" & Chr$(34) & " /runtime", vbMaximizedFocus)
End If
If Not Len(Dir("C:\Program Files\Microsoft Office\Office11\msaccess.exe", vbDirectory)) = 0 Then
Call Shell(Chr$(34) & "C:\Program Files\Microsoft Office\Office11\msaccess.exe" & Chr$(34) & " " & Chr$(34) & "http://stoneplastics/Departments/Quality/Databases/ItemInspectionInstructionPrintOutRev3.accdb" & Chr$(34) & " /runtime", vbMaximizedFocus)
End If
If Not Len(Dir("C:\Program Files\Microsoft Office\Office15\msaccess.exe", vbDirectory)) = 0 Then
Call Shell(Chr$(34) & "C:\Program Files\Microsoft Office\Office15\msaccess.exe" & Chr$(34) & " " & Chr$(34) & "http://stoneplastics/Departments/Quality/Databases/ItemInspectionInstructionPrintOutRev3.accdb" & Chr$(34) & " /runtime", vbMaximizedFocus)
End If
If Not Len(Dir("C:\Program Files (x86)\Microsoft Office\Office14\msaccess.exe", vbDirectory)) = 0 Then
Call Shell(Chr$(34) & "C:\Program Files (x86)\Microsoft Office\Office14\msaccess.exe" & Chr$(34) & " " & Chr$(34) & "http://stoneplastics/Departments/Quality/Databases/ItemInspectionInstructionPrintOutRev3.accdb" & Chr$(34) & " /runtime", vbMaximizedFocus)
End If
If Not Len(Dir("C:\Program Files (x86)\Microsoft Office\Office12\msaccess.exe", vbDirectory)) = 0 Then
Call Shell(Chr$(34) & "C:\Program Files (x86)\Microsoft Office\Office12\msaccess.exe" & Chr$(34) & " " & Chr$(34) & "http://stoneplastics/Departments/Quality/Databases/ItemInspectionInstructionPrintOutRev3.accdb" & Chr$(34) & " /runtime", vbMaximizedFocus)
End If
If Not Len(Dir("C:\Program Files (x86)\Microsoft Office\Office15\msaccess.exe", vbDirectory)) = 0 Then
Call Shell(Chr$(34) & "C:\Program Files (x86)\Microsoft Office\Office15\msaccess.exe" & Chr$(34) & " " & Chr$(34) & "http://stoneplastics/Departments/Quality/Databases/ItemInspectionInstructionPrintOutRev3.accdb" & Chr$(34) & " /runtime", vbMaximizedFocus)
End If
If Not Len(Dir("C:\Program Files (x86)\Microsoft Office\Office11\msaccess.exe", vbDirectory)) = 0 Then
Call Shell(Chr$(34) & "C:\Program Files (x86)\Microsoft Office\Office11\msaccess.exe" & Chr$(34) & " " & Chr$(34) & "http://stoneplastics/Departments/Quality/Databases/ItemInspectionInstructionPrintOutRev3.accdb" & Chr$(34) & " /runtime", vbMaximizedFocus)
End If
If Not Len(Dir("C:\Program Files\Microsoft Office 15\root\office15\msaccess.exe", vbDirectory)) = 0 Then
Call Shell(Chr$(34) & "C:\Program Files\Microsoft Office 15\root\office15\msaccess.exe" & Chr$(34) & " " & Chr$(34) & "http://stoneplastics/Departments/Quality/Databases/ItemInspectionInstructionPrintOutRev3.accdb" & Chr$(34) & " /runtime", vbMaximizedFocus)
End If
看看這個VBA過程:http://stackoverflow.com/questions/37822050/cant-run-dir-from-wscript-shell-in-vba – Tim
我想通了。我確實檢查了它,但沒有奏效。 –