VB6 Shell 函数 - 无效的过程调用或参数 shell

发布于 2024-12-27 13:58:02 字数 394 浏览 0 评论 0原文

我正在尝试运行 shell 函数来使用 Notepad.exe 打开文件

。尝试打开文件时出现“无效的过程调用或参数 shell”错误。

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

有什么想法吗?

I am trying to run a shell function to open a file using Notepad.exe

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

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半城柳色半声笛 2025-01-03 13:58:02

这对我有用:

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 返回类型。)

我相信您遇到的错误是因为您的文件路径包含空格。尝试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

This worked for me:

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

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.)

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
喜爱纠缠 2025-01-03 13:58:02

我认为您的 exe 应用程序旁边有一个文件 Notepad.exe

I think there is a file Notepad.exe located beside your exe application

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文