【问题标题】:Public Declare Function BringWindowToTop Lib "user32" _ Alias "BringWindowToTop" (ByVal hwnd As Long) As Long公共声明函数 BringWindowToTop Lib "user32" _ Alias "BringWindowToTop" (ByVal hwnd As Long) As Long
【发布时间】:2021-02-07 11:14:44
【问题描述】:

当这段代码:

Public Declare Function BringWindowToTop Lib "user32" _
Alias "BringWindowToTop" (ByVal hwnd As Long) As Long

显示错误:

常量、定长字符串、数组、用户定义类型和 Declare 语句不允许作为对象模块的公共成员

请帮我解决错误

【问题讨论】:

  • 错误信息告诉你。 Declare不能进入表单模块,必须在代码模块中。
  • 代码模块又名通用模块,即不在表单或报告后面。
  • 除了确保声明在标准代码模块中之外,您确定不需要 API 的 PtrSafe 版本吗?

标签: vba ms-access


【解决方案1】:

模块(不是表单)中:

#If VBA7 Then
    Public Declare PtrSafe Function BringWindowToTop Lib "user32" _
        (ByVal hwnd As Long) As Long
#Else
    Public Declare Function BringWindowToTop Lib "user32" _
        Alias "BringWindowToTop" (ByVal hwnd As Long) As Long
#End If

【讨论】:

    猜你喜欢
    • 2020-08-28
    • 2012-07-03
    • 1970-01-01
    • 2019-03-10
    • 1970-01-01
    • 2010-10-02
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    相关资源
    最近更新 更多