示例10:检查是否所有的ActiveX控件都有数据 Privatedict As Dictionary Set dict =CreateObject('scripting.dictionary') For Each it In Array('TextBox1', 'TextBox2','textbox3', 'combobox4', 'combobox5') Set dict(it) =Sheets('sheet1').OLEObjects(it) Next EndSub M_controle EndSub y = True For Each it Indict.Items y = y *(it.Object.Value<> '') Next Sheets('sheet1').CommandButton1.Visible = y EndSub
示例11:检查工作表是否存在 在标准模块中的代码: Publicdict_sheets As Dictionary 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
本文属原创文章,转载请注明出处。 欢迎在下面留言,完善本文内容,让更多的人学到更完美的知识。 |
|