|
搞了一个按钮,以方便操作
原贴见http://club.excelhome.net/thread-86482-1-1.html
感谢shuiyuan等坛友的付出
-
- '------------------------以下内容放在ThisWorkBook中-------------------
- Private Sub Workbook_BeforeClose(Cancel As Boolean)
- Application.CommandBars("MyBar").Delete
- End Sub
- Private Sub Workbook_Open()
- Application.CommandBars.Add(Name:="MyBar", Position:=msoBarRight).Visible = True
- NewFace
- End Sub
- '-----------------------以下内容放在模块1中--------------------------
- Option Explicit
- Sub NewFace()
- Dim Newbutton As CommandBarControl
- Dim myPic1, myPic2, myTxt As String
- Dim foundFlag As Boolean
- Dim cb As CommandBarControl
-
- myPic1 = "R1.bmp" 'R1C1图片请自行调整路径
- myPic2 = "A1.bmp" 'A1图片
- With Application
- If .ReferenceStyle = xlR1C1 Then
- myTxt = myPic2
- Else
- myTxt = myPic1
- End If
- End With
- foundFlag = False
- For Each cb In CommandBars("MyBar").Controls
- If cb.Caption = "转换" Then
- cb.Visible = True
- foundFlag = True
- End If
- Next cb
- With Application
- If Not foundFlag Then
- Set Newbutton = .CommandBars("MyBar").Controls.Add(Type:=msoControlButton, Before:=1)
- With Newbutton
- .Picture = LoadPicture(myTxt)
- .Style = msoButtonIcon '图像
- .Caption = "转换" '标题
- .Visible = True '显示
- .OnAction = "RC_A1" '运行指定的过程名
- End With
- Else
- Set Newbutton = .CommandBars("MyBar").Controls(1)
- With Newbutton
- .Picture = LoadPicture(myTxt)
- .Style = msoButtonIcon '图像
- .Caption = "转换" '标题
- .Visible = True '显示
- .OnAction = "RC_A1" '运行指定的过程名
- End With
- End If
- End With
- End Sub
- '----------------------
- 'R1C1样式与A1样式的转换
- '
- Private Sub RC_A1()
- With Application
- If .ReferenceStyle = xlR1C1 Then
- .ReferenceStyle = xlA1
- Else
- .ReferenceStyle = xlR1C1
- End If
- End With
- Call NewFace
- End Sub
复制代码
个人经验,存为加载项(.xla),这样可以在EXCEL启动时随时调用.
Enjoy with Excel |
-
-
img.rar
572 Bytes, 下载次数: 33
R1.bmp与A1.bmp解压使用
评分
-
1
查看全部评分
-
|