【问题标题】:VBA, Array based on check box values?VBA,基于复选框值的数组?
【发布时间】:2016-04-13 14:24:08
【问题描述】:

大家早上好。我在尝试让按钮在 Excel 2007、VBA 中正常工作时遇到了一些困难。此按钮的作用是根据复选框值为 true 对工作表进行分组。然后它将显示打印对话框,以便用户可以打印到 PDF 或他们的打印机。

我不知道该怎么做。我确实尝试过使用:

If me.chkTable1 = True Then Sheets(Table3.Name).Select
If me.chkTable2 = True Then Sheets(Table4.Name).Select

但是我发现使用这种方法之前的工作表将取消选择。我想也许一个数组会起作用。如果 me.chkTableX 的值 = True 则数组将填充工作表。然后最后我可以选择要打印的数组。

我是新手,如有遗漏,敬请见谅。

【问题讨论】:

    标签: arrays excel excel-2007 vba


    【解决方案1】:

    这样的事情会起作用:

    Sub sheetselect()
    Dim wsStr() As Variant
    Dim ostr() As Variant
    
    ReDim wsStr(0 To 0)
    
    If Me.chktable1 = True Then
        wsStr(UBound(wsStr)) = table3.Name
        ReDim Preserve wsStr(UBound(wsStr) + 1) As Variant
    End If
    If Me.chktable2 = True Then
        wsStr(UBound(wsStr)) = table4.Name
        ReDim Preserve wsStr(UBound(wsStr) + 1) As Variant
    End If
    ReDim ostr(0 To UBound(wsStr) - 1)
    For k = 0 To UBound(wsStr) - 1
        ostr(k) = wsStr(k)
    Next k
    Sheets(ostr).Select
    End Sub
    

    它加载一个包含工作表名称的数组。然后使用这个数组来选择合适的工作表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 2012-03-27
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多