Tag: 表单

用户窗体包含文本框和checkboxinput到工作表

用户一次最多可以input10个成员。 Column A will be "Team Number" Column B will be "Number of Member" Column C will be "Member Name" Column D will be "Month Available" Column E will be "Number of Family Members Coming" Column F will be "Family Members" 我无法尝试input到工作表的用户窗体值。 'inputValue Dim RowCount As Long Dim rStart As Long Dim rFirstEnd As Long […]

确认至less有一个checkbox被选中

我有search相同的问题,我看到了一些类似的职位,但我的用户表单仍然无法正常工作。 我是VBA和Userform的新手。 我总共有12个checkbox(12个月),我必须检查至less有一个checkbox被选中。 Dim atLeastOneChecked As Boolean atLeastOneChecked = False Dim ctrlNCK As Control For Each ctrlNCK In Controls If TypeName(ctrlNCK) = "chkMonth" Then If ctrlNCK.Value = True Then atLeastOneChecked = True End If Next ctrlNCK If Not atLeastOneChecked = True Then MsgBox "Month cannot be empty.", vbExclamation, "Input Data" Exit Sub End If

从2列中获取最后一行,然后将数据input到列的1中

在发布这个问题之前,我做了一个search。 我发现的结果只是find1列的最后一行,我想find2列的最后一行,然后相应地input数据。 希望你们可以帮忙。 谢谢! 🙂 If optMemberName.Value = True Then With Sheets("Sheet1") Range("A" & .Cells(.Rows.Count, "A").End(xlUp).Row) = txtMemberName.Text End With ElseIf optMemberID.Value = True Then With Sheets("Sheet1") Range("B" & .Cells(.Rows.Count, "B").End(xlUp).Row) = txtMemberID.Text End With End If 这是现在的输出 这是用户表单的样子 这是我想要的输出

在用户窗体中打开应用程序

Scott Beeson曾经在这里发布了以下代码来激发用户表单中的应用程序: Public Class Form1 Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Private Const WM_SYSCOMMAND As Integer = 274 Private Const SC_MAXIMIZE […]

OptionButton决定在macros中使用的值

一个基本的简单的VBA问题,我还没有能够解决,即使有很多关于它的教程。 我想要一个用户窗体popup,给你两个选项(OptionButton1和OptionButton2)。 你select一个,点击确定。 并根据select什么选项使用某个值(在一个电子邮件,我DID完成macros)。 为了简化目的,我现在只想在单元格A1中打印variables“内容”。 到目前为止,我有这些部分: Sub MailOption() UserForm1.Show End Sub Private Sub OptionButton1_Click() If OptionButton1.Value = True Then Var1 = "Text example 1" End Sub Private Sub OptionButton2_Click() If OptionButton2.Value = True Then Var1 = "Text example 2" End Sub Private Sub SendEmail_Click() Cells(1, 1).Value = Var1 End Sub 有多个问题:variables不显示在单元格A1中,当我按下发送电子邮件时,表单未closures。 我可能做了很多错误的东西,但它是第一次使用用户窗体。 泰非常

为什么在从用户窗体启动一个用户窗体后,closures两个窗体呢?

工作表上的一个button启动一个macros,打开一个用户窗体(比如userform1)。 Userform1被加载非模态,以便用户使用userform1和工作表(即单击单元格)进行input。 userform1上有一个button,点击后会打开另一个用户窗体(比如userform2)。 Userform2是模态的。 点击userform2上的Cancelbutton,卸载userform2; 但是,出于某种原因,它也卸载了userform1,我不想要。 如果我使用userform1模式,那么卸载userform2不会卸载userform1; 但是,用户不能再使用(即单击)工作表中的单元格。 我无法find任何信息,这将给我一个线索,为什么卸载一个用户窗体都卸载。

如何在主模块中使用input到userform的数据

我用VBA编码很新。 我有一个用五个TextBoxes的用户窗体。 用户将在第一个文本框和最后四个文本框中的单元格位置(例如A1)中input一个整数。 我想要在主模块中使用这些数据。 我需要在循环中使用整数,即循环,直到计数器达到该整数。 我需要使用单元格位置开始访问不同的数据集,这些数据集可能在工作表中的任何位置。 我在主模块中访问这些数据时遇到问题。 当用户点击确定button时,我目前隐藏窗体。 为了testing我的代码,我只是将文本框中的数据写入单元格。 来自主模块的代码: Sub Sort2Stack() UserInput.Show Cells(5, 22).Value = TestPeriod.Value 'integer entered in TextBox 1 Cells(6, 22).Value = YMLoc.Value 'cell location entered in TextBox 2 Cells(7, 22).Value = YFLoc.Value ' . Cells(8, 22).Value = NMLoc.Value ' . Cells(9, 22).Value = NFLoc.Value 'cell location entered in TextBox 5 End […]

Excel VBA – 无法引用对象/不能将信息放入工作表中

我有一个接口,我正在做一些问题。 我是新来的,经过很多的search,我终于放弃了,来到这里问。 首先,我让我的代码这样做: 从工作表上的button打开一个用户表单。 在用户窗体打开后,它有一些默认的字段(一些文本框,一个标签和一个命令button)。 然后你有一个命令button,创build一个新的一轮领域,并为他们分配一个类来执行一些简单的代码(数字限制一些文本框,并创build一个新的文本框与button的内容)。 我的问题是以下几点: 我试图将ControlSource分配给字段,但Excel不允许我,只有它允许我,字段没有更新单元格,也没有单元格更新字段。 我也尝试从新创build的字段的值直接加载到工作表,但我不知道如何调用该对象,并获得其属性。 这是我正在使用的代码: Option Explicit Dim cargarconcepto() As New Clase3 Private Sub CommandButton19_Click() Dim txtCtl As Control Dim concepto As Object Dim i As Long i = labelcounter controlextra = controlextra + 1 Dim Label As Object Dim lblctr As Long Dim nmctr As Long Dim t1 As […]

当工作簿closures时,子例程意外结束

我今天的问题是一个子程序的一部分,当一个Workbook被closures时,这个子程序莫名其妙地中断了它的执行。 我写了下面的代码: Public Const Pi As Double = 3.14159265358979 Public Const Rad As Double = Pi / 180 Public CalcBook As Workbook Public FilePath As String, Files() As String Public FreqArray() As Integer Sub Main() Dim ChooseFolder As Object, FilePath As String, StrFile As String Dim i As Integer, j As Integer, k As Integer, […]

将事件处理程序分配给在VBA中dynamic创build的用户窗体上的控件到子项中

我的问题与这一个有关 。 我创build了一个类: Public WithEvents btn As MSForms.CommandButton Private Sub btn_Click() MsgBox "Hello" End Sub 下面的代码运行良好。 我的意思是显示10个button,点击后,出现消息框。 Dim collBtns As Collection Public Sub UserForm_Initialize() Dim btn As CommandButton Dim btnH As cButtonHandler Set collBtns = New Collection For k = 1 To 10 Set btn = testform.Controls.Add("Forms.CommandButton.1", True) With btn .Caption = "Title" .Left = […]