适用于MacOS的Excel 2018用户表单 [英] Userform with Excel 2018 for MacOS
问题描述
我看到无法将用户窗体添加到Excel 2018 for MacOS
(或者自Excel 2016起)的功能与Excel 2011不同:当我说添加用户窗体"时,我在谈论"UI 允许设计按钮,框,列表等的设计器.(实际上,似乎只有Windows版本的Excel 2018才提供添加用户窗体的功能.
I saw that functionality of adding userform into Excel 2018 for MacOS
(or since Excel 2016) was not possible unlike with Excel 2011 : when I say "adding userform", I am talking about the "UI" designer which allows to design the buttons, boxes, lists, ... (Actually it seems that adding userform is only available on Windows version of Excel 2018).
即使我有其他语言的编程基础,我还是VBA脚本的初学者.
I am a beginner in VBA scripting even if I have basics of programming in others languages.
任何人都可以给我一个简单的示例或教程链接,以了解如何使用Excel 2018 for MacOS构建简单的用户窗体吗?
Could anyone give me a simple example or a tutorial link how to build a simple userform with Excel 2018 for MacOS ?
如果"UI"设计器不可用,我可以仅使用VBA代码源直接对用户表单进行编码(可以直接对设计进行编码吗?)
If the "UI" designer is not available, can I directly code the userform with only a VBA code source ( can the design be directly coded ?)
谢谢您的帮助
推荐答案
通过编程方式抓取的屏幕截图Mac版Excel中生成的UserForm对象-Microsoft 365
必须通过在与ThisWorkbook对象关联的VBProject的VBComponents集合上调用Add()方法来生成userform对象,如下所示:
The userform object had to be generated by invoking the Add() method on the VBComponents collection of the VBProject associated with the ThisWorkbook object, as follows:
Set objForm = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
这创建了一个名为UserForm1的用户窗体对象.我简要地看到了可视化编辑器,并能够为新创建的表单拖放标签控件和命令按钮,但随后的尝试均失败了.
This created a userform object named UserForm1. I briefly saw the visual editor and was able to drag and drop a label control and a command button,for the newly created form but subsequent attempts failed.
因此,我向UserForm_Initialize()事件过程添加了代码,以手动定位和配置现有控件.我还向自动生成的CommandButton1_Click()事件过程存根中添加了代码.
So I added code to the UserForm_Initialize() event procedure, manually positioning and configuring the existing controls. I also added code to the automatically generated CommandButton1_Click() event procedure stub.
Option Explicit
Private Sub CommandButton1_Click()
MsgBox prompt:="Bye for now!"
Unload Me
End Sub
Private Sub UserForm_Initialize()
Me.Height = 200
Me.Width = 500
Me.Caption = "UserForm On MacOS!!"
With Me.CommandButton1
.Top = 10
.Left = 400
.Width = 50
.Height = 30
.Caption = "OK!"
.Font.Size = 20
.Font.Bold = True
End With
With Me.Label1
.Caption = "Hallelujer!"
.Width = 120
.Height = 30
.Left = 5
.Top = 10
.BorderStyle = fmBorderStyleSingle
.SpecialEffect = fmSpecialEffectEtched
With .Font
.Name = "Arial"
.Size = 20
.Bold = True
End With
End With
End Sub
通过附加在功能区上自定义按钮上的宏调用表单.
The form is invoked via a macro attached to a custom button on the Ribbon.
Public Sub MakeForm()
Dim objForm As UserForm
'Execute the following statement once for each userform object to be created
'and then disable it
'Set objForm = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
'Display the userform
UserForm1.Show
End Sub
这似乎表明可以将UserForm控件插入VBProject.
This seems to demonstrate that it is possible to insert a UserForm control into a VBProject.
这还表明,UserForm支持的基础确实存在于Mac版Excel中,但它们尚未完全实现.
It also suggests that the underpinnings of UserForm support do indeed exist in Excel for Mac but they are as of yet not fully implemented.
这篇关于适用于MacOS的Excel 2018用户表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!