vba OpenProcess 给出“未定义子或函数”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4336170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:22:31  来源:igfitidea点击:

OpenProcess gives "Sub or Function not defined" error

vbaexcel-vbaexcel

提问by rryanp

I'm using VBA in Excel and am trying to use the popular ShellAndWait subroutine. Within this sub is a call to OpenProcess, but that is giving me a compile error "Sub or Function not defined." I've tried to research why this would come up and can't find anything. Is there a specific Reference I need to set up in VBA to use this? I don't have admin rights on this machine--could that be a problem? Thanks for any insight.

我在 Excel 中使用 VBA 并尝试使用流行的 ShellAndWait 子例程。在这个 sub 中是对 OpenProcess 的调用,但这给了我一个编译错误“Sub or Function not defined”。我试图研究为什么会出现这种情况并且找不到任何东西。是否需要在 VBA 中设置特定的参考才能使用它?我在这台机器上没有管理员权限——这会不会有问题?感谢您的任何见解。

回答by DReJ

Have you declared OpenProcess?

您是否已声明 OpenProcess?

Declare Function OpenProcess Lib “kernel32” (ByVal dwDesiredAcess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long