VBA进阶 | Dictionary对象应用大全10:示例(续3)

VBA进阶 | Dictionary对象应用大全10:示例(续3)

示例10:检查是否所有的ActiveX控件都有数据

Privatedict As Dictionary



Sub M_vul()

      Set dict =CreateObject("scripting.dictionary")

      For Each it In Array("TextBox1", "TextBox2","textbox3", "combobox4", "combobox5")

            Set dict(it) =Sheets("sheet1").OLEObjects(it)

Next

EndSub



Private Sub Textbox1_change()

M_controle

EndSub



Private Sub M_controle()

            y = True 

            For Each it Indict.Items

    y = y *(it.Object.Value<> "") 

Next

Sheets("sheet1").CommandButton1.Visible = y

EndSub

 

示例11:检查工作表是否存在

在标准模块中的代码:

Publicdict_sheets As Dictionary



Sub M_sheet_exists()

        Set dict_sheets =CreateObject("scripting.dictionary")

        For Each it In Sheets

x0 =dict_sheets(it.name)

  Next

EndSub

 

现在,可以在

VBproject (Workbook)

的任何地方使用:

SubM_continue()

      " - - - If Notdict_sheets.Exists("Sheet10") Then Sheets.Add.Name ="Sheet10"

      " - - -

EndSub

 

示例12:转换文本字符串为二维数组

SubConvertStrToArray()

    Dim it

    WithCreateObject("scripting.dictionary")

        For Each it InSplit("aa1_aa2_aa3_aa4_aa5|bb1_bb2_bb3_bb4_bb5|cc1_cc2_cc3_cc4_cc5","|")

            .Item(.Count) =Application.Index(Split(it, "_"), 1, 0)

        Next

 

Cells(10,1).Resize(.Count, UBound(.Item(1))) = Application.Index(.Items, 0, 0)

    End With

EndSub

 



本文属原创文章,转载请注明出处。

欢迎在下面留言,完善本文内容,让更多的人学到更完美的知识。

欢迎关注

[

完美

Excel

]

微信公众号:

方法

1

—在微信通讯录中搜索“

完美

Excel

”或者“

excelperfect

”后点击关注。

方法

2

—扫一扫下面的二维码

VBA进阶 | Dictionary对象应用大全10:示例(续3)