使用 shell32.dll 声明函数 Excel Vba

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12042458/
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 17:23:36  来源:igfitidea点击:

Declare Function Excel Vba using shell32.dll

excelshellexcel-vbawindows-shellshellexecutevba

提问by derigible

Can someone tell me what is going on with the code below:

有人可以告诉我下面的代码发生了什么:

'Variables at top of module or some function/sub here

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

 'some function or sub routine here

This code shows the position of the function declare. I am not familiar with what the declare keyword is doing, nor do i understand why this is not compiling.

此代码显示函数声明的位置。我不熟悉 declare 关键字在做什么,也不明白为什么这不能编译。

I got this when I was looking up ways to open tabs in internet explorer through vba, but I can't seem to get it to work.

我在寻找通过 vba 在 Internet Explorer 中打开选项卡的方法时得到了这个,但我似乎无法让它工作。

It seems as though the compiler does not recognize this as a function, but I have seen several forum posts that use this code without it having any problems (this oneincluded).

似乎编译器没有将其识别为函数,但我已经看到几个论坛帖子使用此代码而没有任何问题(包括这个)。

It seems as though I may be missing a reference, or possibly the dll, but i don't see the library as a reference in the tools menu, and i don't know how to check if i have this on my machine.

似乎我可能缺少一个引用,或者可能是 dll,但我没有在工具菜单中看到该库作为引用,而且我不知道如何检查我的机器上是否有这个。

If someone could point me in the right direction that would be great.

如果有人能指出我正确的方向,那就太好了。

采纳答案by Tim Williams

An API declaration is like a regular variable declaration: it must be at the top of the module, before any Subs/Functions.

API 声明就像一个普通的变量声明:它必须在模块的顶部,在任何 Subs/Functions 之前。