|
楼主 |
发表于 2010-9-30 21:23
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Set myPop = mybar.Controls.Add(msoControlPopup, , , , True)
myPop.Caption = .Cells(i, "A")
比这种写法理解起来容易点。
Set 新功能表按鈕 = 工具列.Controls.Add(Type:=msoControlPopup, Temporary:=True)- Sub Create_popup()
- On Error Resume Next
- 'Dim i As Byte
- Dim i As Long
- CommandBars("myR").Delete
- Dim mybar As CommandBar
- Set mybar = Application.CommandBars.Add("myR", msoBarPopup, , True)
- mybar.Height = 500
- mybar.Width = 400
-
- Dim myPop As CommandBarPopup
- Dim myBtn As CommandBarButton
- Dim Pop() As CommandBarPopup
- Dim Pop1() As CommandBarPopup
- Dim n As Integer
- Dim n1 As Integer
- n = 1
- n1 = 1
- Dim dc As Object
- Dim dc1 As Object
- Set dc = CreateObject("scripting.dictionary")
- Set dc1 = CreateObject("scripting.dictionary")
-
- With Sheets("商品名称数源")
- For i = 1 To .[a65536].End(3).Row
- 'For i = 2 To .[a65536].End(3).Row
- Next
- For i = 1 To .[a65536].End(3).Row
- 'For i = 2 To .[a65536].End(3).Row
- If .Cells(i, "A").Font.ColorIndex = 3 Then
- Set myPop = mybar.Controls.Add(msoControlPopup, , , , True)
- myPop.Caption = .Cells(i, "A")
- bl = True
- Else
- If .Cells(i, "D") <> "" Then
- If Not dc.exists(.Cells(i, "D").Value) Then
- dc.Add .Cells(i, "D").Value, n
- ReDim Preserve Pop(n) As CommandBarPopup
- Set Pop(n) = myPop.Controls.Add(msoControlPopup, , , , True)
- Pop(n).Caption = .Cells(i, "D")
- n = n + 1
- End If 'If Not dc.exists(.Cells(i, "D").Value)
-
- If .Cells(i, "E") <> "" Then
- If Not dc1.exists(.Cells(i, "E").Value) Then
- dc1.Add .Cells(i, "E").Value, n1
- ReDim Preserve Pop1(n1) As CommandBarPopup
- Set Pop1(n1) = Pop(dc.Item(.Cells(i, "D").Value)).Controls.Add(msoControlPopup, , , , True)
- Pop1(n1).Caption = .Cells(i, "E")
- n1 = n1 + 1
- End If
- Set myBtn = Pop1(dc1.Item(.Cells(i, "E").Value)).Controls.Add(msoControlButton)
- myBtn.Caption = .Cells(i, "A")
- myBtn.HelpFile = .Cells(i, 2) & "," & .Cells(i, 3)
- myBtn.Style = msoButtonCaption
- myBtn.OnAction = "myBtn_click"
- Else
-
- Set myBtn = Pop(dc.Item(.Cells(i, "D").Value)).Controls.Add(msoControlButton)
- myBtn.Caption = .Cells(i, "A")
- myBtn.HelpFile = .Cells(i, 2) & "," & .Cells(i, 3) '2010年5月5日:将单价和单位信息保存到按钮的Helpfile属性中,然后在mybtn_click事件中取出。
- myBtn.Style = msoButtonCaption
- myBtn.OnAction = "myBtn_click"
- End If
-
- Else
- Set myBtn = myPop.Controls.Add(msoControlButton)
- myBtn.Caption = .Cells(i, "A")
- myBtn.HelpFile = .Cells(i, 2) & "," & .Cells(i, 3) '2010年5月5日:将单价和单位信息保存到按钮的Helpfile属性中,然后在mybtn_click事件中取出。
- myBtn.Style = msoButtonCaption
- myBtn.OnAction = "myBtn_click"
- End If 'If .Cells(i, "D") <> "" Then
- End If 'If .Cells(i, "A").Font.ColorIndex = 3 Then
- Next
- End With
-
- Set myBtn = Nothing
- Set myPop = Nothing
- Set mybar = Nothing
- Set dc = Nothing
- Set dc1 = Nothing
- Erase Pop
- Erase Pop1
- End Sub
复制代码
[ 本帖最后由 ningyong58 于 2010-10-2 10:23 编辑 ] |
|