Excel表单中的条件复选框选项

时间:2018-11-09 15:06:39

标签: excel vba excel-vba

这个问题超出了我的技能范围-我以前从未以“实时”形式使用按钮或复选框。我将两个Excel表单组合在一起以创建一个主表单。虽然非常相似,但加利福尼亚的表单具有其他选项来检查其“国家”表单没有的提供者列表类型。

enter image description here

我想做的是在顶部选择“加利福尼亚”,并提供“区域提供商列表”和“加利福尼亚完整列表(CD)”作为选项,而如果我选择“国家”,则不可用。许多不同的人都会使用此表单,因此我需要确保他们无法单击所需的任何内容。我不是一个强大的编码器,而是其他人构建了表单,我只是将它们混在一起。我能理解的大多数解决方案都是针对ActiveX控件的,并且我使用了简单的Form控件。我也很抱歉张贴整个代码,但我不确定要在哪里插入复选框控制代码。如果有人可以向他们推荐新手方面的优秀资源,那么我将不胜感激。

Option Explicit

Function checkComplete()

'Dim TextBox1 As OLEObject

If IsEmpty(Range("I6")) Then
    MsgBox "Please enter the Claimant Name."
    Range("I6").Select
    checkComplete = False
ElseIf IsEmpty(Range("I8")) Then
    MsgBox "Please enter the Claim #."
    Range("I8").Select
    checkComplete = False
ElseIf IsEmpty(Range("AF6")) Then
    MsgBox "Please enter the Date that the list is needed by."
    Range("AF6").Select
    checkComplete = False
'ElseIf TextBox1.Text = "" Then
    'MsgBox "Please enter a description."
    'TextBox1.Select
    'checkComplete = False
Else
    checkComplete = True
End If

End Function

  Sub submitForm()

  If checkComplete = False Then Exit Sub

  Dim thisWb As Workbook, wbTemp As Workbook
  Dim ws As Worksheet

  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  Application.EnableEvents = False

  Set thisWb = ThisWorkbook
  Set wbTemp = Workbooks.Add

    'Save Network Development Form worksheet to new workbook.
     'Needs to be copied from an xltm to an xlsx workbook in order to email a good xlsx file that is not corrupt.
 thisWb.Sheets(1).Copy After:=wbTemp.Sheets(3)

 For Each ws In wbTemp.Worksheets
    If ws.Name <> "Network Development Form" Then
        ws.Delete
    End If
 Next

 ActiveWindow.ScrollRow = 1

 'Save temporary copy of workbook
 Dim TempFilePath As String
 Dim TempFileName As String
 Dim FileExtStr As String

 TempFilePath = Environ$("temp") & "\"
 TempFileName = "Network Development - Claim#" & Range("I8").Value
 FileExtStr = ".xlsx"

 Set wbTemp = ActiveWorkbook
 wbTemp.SaveCopyAs TempFilePath & TempFileName & FileExtStr

'Email copy of form to Networks
 Dim outlook As Object
 Dim outlookMail As Object
 Dim UName As Variant

 Set outlook = CreateObject("Outlook.Application")
 Set outlookMail = outlook.CreateItem(0)
 UName = Environ("UserName")

 With outlookMail
    .To = ""
    .CC = UName & "@auw.com"
    .Subject = "Network Development Form"
    .Attachments.Add TempFilePath & TempFileName & FileExtStr
    .Send '.Display
 End With

 Kill TempFilePath & TempFileName & FileExtStr

 Set outlook = Nothing
 Set outlookMail = Nothing

 wbTemp.Activate
 wbTemp.Close SaveChanges:=False

 thisWb.Activate

 Application.ScreenUpdating = True
 Application.DisplayAlerts = True
 Application.EnableEvents = True

 thisWb.Close SaveChanges:=False

 End Sub

0 个答案:

没有答案