VB6 Shell 函数 - 无效的过程调用或参数 shell [英] VB6 Shell Function - Invalid procedure call or argument shell
本文介绍了VB6 Shell 函数 - 无效的过程调用或参数 shell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试运行 shell 函数来使用 Notepad.exe 打开文件
I am trying to run a shell function to open a file using Notepad.exe
我在尝试打开文件时收到无效的过程调用或参数 shell"错误.
I get the "invalid procedure call or argument shell" error when trying to open a file.
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
类型声明字符被认为是遗留代码,所以我通过声明来避免它们.(不过我将它们与 Shell/Trim/Chr 一起使用以避免 Variant 返回类型.)
Type-declaration characters are considered legacy code, so I avoid them with declarations. (However I used them with Shell/Trim/Chr to avoid the Variant return type.)
我相信您遇到的错误是因为您的文件路径包含空格.尝试 WSHOM 代替:
I believe the error you are experiencing is because your filepath contains spaces. Try the WSHOM instead:
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
这篇关于VB6 Shell 函数 - 无效的过程调用或参数 shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文