excel - 用户表单在 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
解决方案
推荐阅读
- c++ - 从私有变量继承的函数是什么意思(C++)?
- reactjs - 解决:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions
- c# - IIS 无法读取 web.config,消息中没有错误详细信息
- video.js - 如何使用 video.js 在 m3u8 中选择频道
- amazon-web-services - 如何在应用级别识别来自 EKS LoadBalancer 的传入请求?
- javascript - 任何人都可以看到我的错误?切换语句
- elixir - 取第 n 个列表
- excel - Office JS:在多个 Excel 实例中执行 Addin 时出现问题
- python - 如何将列表中的 dict 拆分为 df
- javascript - 使用动态对象数组在 React 中渲染 html 表