excel怎样添加的选项卡中含有下拉列表

Posted 猪冰龙

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了excel怎样添加的选项卡中含有下拉列表相关的知识,希望对你有一定的参考价值。

 1 <customUI 
 2   xmlns="http://schemas.microsoft.com/office/2006/01/customui">
 3   <ribbon startFromScratch="false">
 4     <tabs>
 5       <tab id="myxxk"
 6         insertBeforeMso="TabHome"
 7         label="我的选项卡">
 8         <group id="cxgroup"
 9           label="查询">
10           <box id="rxbox1"
11             boxStyle="vertical">
12             <box id="rxbox11"
13               boxStyle="horizontal">
14               <comboBox 
15                 id="ks_n"
16                 label="开始日期:"
17                 onChange="ksn_Click"
18                 getItemCount="nCount"
19                 getItemID="nID"
20                 getItemLabel="nLabel" 
21                 getText="nMoren">
22               </comboBox>
23               <comboBox 
24                 id="ks_y"
25                 sizeString="9999"
26                 onChange="ksy_Click"
27                 getItemCount="yCount"
28                 getItemID="yID"
29                 getItemLabel="yLabel" 
30                 getText="yMoren">
31               </comboBox>
32             </box>
33             <box id="rxbox21"
34               boxStyle="horizontal">
35               <comboBox 
36                 id="js_n"
37                 label="结束日期:"
38                 onChange="jsn_Click"
39                 getItemCount="nCount"
40                 getItemID="nID"
41                 getItemLabel="nLabel" 
42                 getText="nMoren">
43               </comboBox>
44               <comboBox 
45                 id="js_y"
46                 sizeString="9999"
47                 onChange="jsy_Click"
48                 getItemCount="yCount"
49                 getItemID="yID"
50                 getItemLabel="yLabel" 
51                 getText="yMoren">
52               </comboBox>
53             </box>
54           </box>
55           <button id="chaxun"
56             image="chaxun"
57             label=" 开始查询 &#x0D;"
58             size="large"
59             onAction="chaxun_click"/>
60         </group>
61       </tab>
62     </tabs>
63   </ribbon>
64 </customUI>
custom ui editor for microsoft office 打开excel中写入的代码
 1 \'生成年份下拉框选项文本
 2 Public ksrq As Date, jsrq As Date
 3 Sub nCount(control As IRibbonControl, ByRef returnedVal)
 4     returnedVal = 16
 5 End Sub
 6 Sub nID(control As IRibbonControl, index As Integer, ByRef id)
 7     id = control.id & index
 8 End Sub
 9 Sub nLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
10     returnedVal = 2000 + index & ""
11 End Sub
12 
13 \'生成月份下拉框选项文本
14 Sub yCount(control As IRibbonControl, ByRef returnedVal)
15     returnedVal = 12
16 End Sub
17 Sub yID(control As IRibbonControl, index As Integer, ByRef id)
18     id = control.id & index
19 End Sub
20 Sub yLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
21     returnedVal = index + 1 & ""
22 End Sub
23 
24 
25 \'设置默认值
26 Sub nMoren(control As IRibbonControl, ByRef returnedVal)
27     returnedVal = IIf(Left(control.id, 1) = "k", "2010年", "2015年")
28 End Sub
29 Sub yMoren(control As IRibbonControl, ByRef returnedVal)
30     returnedVal = IIf(Left(control.id, 1) = "k", "1月", "12月")
31 End Sub
32 
33 
34 \'选择年月,保存到变量
35 Sub ksn_Click(control As IRibbonControl, text As String)
36     ksrq = DateSerial(Val(Left(text, 4)), Month(ksrq), 1)
37 End Sub
38 Sub ksy_Click(control As IRibbonControl, text As String)
39     ksrq = DateSerial(Year(ksrq), Val(LeftB(text, 2)), 1)
40 End Sub
41 Sub jsn_Click(control As IRibbonControl, text As String)
42     jsrq = DateSerial(Val(Left(text, 4)), Month(jsrq) + 1, 0)
43 End Sub
44 Sub jsy_Click(control As IRibbonControl, text As String)
45     jsrq = DateSerial(Year(jsrq), Val(LeftB(text, 2)) + 1, 0)
46 End Sub
47 
48 
49 \'点击查询按钮
50 Sub chaxun_click(control As IRibbonControl)
51     MsgBox "开始日期:" & Format(ksrq, "yyyy-mm-dd") & Chr(13) _
52     & "结束日期:" & Format(jsrq, "yyyy-mm-dd")
53 End Sub
vba中需要配合的代码

http://club.excelhome.net/forum.php?mod=viewthread&tid=709306&extra=page%3D1

 

以上是关于excel怎样添加的选项卡中含有下拉列表的主要内容,如果未能解决你的问题,请参考以下文章

如何导出excel中下拉菜单的内容?

在引导选项卡中选择 2 挤压下拉列表

Excel动态下拉列表按过滤表

如何在片段选项卡中添加另一个活动(例如视频活动)?

怎样在excel下拉中字母递增?

下拉列表内容怎么设置?