首页 > 解决方案 > 用户表单在 excel 中仅显示 3 个命令按钮中的 1 个

问题描述

我是 VBA 新手,我开发了一个 32 位的 excel 文件(.xlsb)。为了使其与 64 位兼容,我还在我的模块中添加了 Ptrsafe 代码,并且我的代码也可以在 64 位编译时没有任何错误。工作表上有一个按钮,显示带有 3 个命令按钮的用户表单。添加 PtrSafe 代码后,没有错误,但用户窗体仅显示 1 个命令按钮,其中 3 个 64 位,我不知道为什么。如果有人可以帮助我,那就太好了。

Private Sub UserForm_Initialize()
Application.EnableCancelKey = xlDisabled

    Me.Caption = DI_Name
    Dim lngWindow As Long, lFrmHdl As Long
    lFrmHdl = FindWindowA(vbNullString, Me.Caption)
    lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE)
    Call SetWindowLong(lFrmHdl, -20, 500)
    Call DrawMenuBar(lFrmHdl)

     Dim AppXCenter, AppYCenter As Long
    AppXCenter = Application.Left + (Application.Width / 2)
    AppYCenter = Application.Top + (Application.Height / 2)
    With Me
        .StartUpPosition = 0
        .Top = AppYCenter - (Me.Height / 2)
        .Left = AppXCenter - (Me.Width / 2)
    End With
End Sub

#If VBA7 Then
    Const GWL_STYLE = -16
    Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare PtrSafe Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If

当我调用表格时,我将其保留为:

vbaform.Show vbModeLess

标签: excelvba64-bit32bit-64bituserform

解决方案


推荐阅读