我想运行一个shell函数打开使用Notepad.exe的文件
试图打开一个文件时,我得到了“无效的过程调用或参数壳”的错误。
Sub OpenTextFile(textfile$)
Dim txtapp$, arg$
txtapp = "Notepad.exe"
textfile = "C:\Users\ADMIN\Desktop\USA - FLNG\modelout\SUMMER.CFS"
arg = Trim$(txtapp & " " & Chr$(34) & Trim$(textfile) & Chr$(34))
ierr = Shell(arg, vbNormalFocus)
End Sub
有任何想法吗?
这为我工作:
Sub OpenTextFile(textfile As String)
Const txtapp As String = "Notepad.exe"
Dim arg As String
Dim ierr As Double
arg = Trim$(txtapp & " " & Chr$(34) & Trim$(textfile) & Chr$(34))
ierr = Shell#(arg, vbNormalFocus)
End Sub
类型声明字符被认为是旧代码,所以我尽量避免他们的声明。 (不过我用它们与壳牌/修剪/ chr将避免变返回类型。)
我相信你所遇到的错误是因为你的文件路径包含空格。 尝试WSHOM来代替:
Sub OpenTextFile(textfile As String)
Dim oShell As Object
Set oShell = GetShell
If Not oShell Is Nothing Then
oShell.Run textfile
End If
End Sub
Function GetShell() As Object
On Error Resume Next
Set GetShell = CreateObject("WScript.Shell")
End Function
我觉得这是位于你的EXE应用程序旁边一个文件Notepad.exe的