1. 程式人生 > >excel怎樣添加的選項卡中含有下拉列表

excel怎樣添加的選項卡中含有下拉列表

tar more combo page targe amp 設置 date mic

技術分享

技術分享
 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怎樣添加的選項卡中含有下拉列表