ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > 我的酷贴 > Excel VBA > 用VBA创建一个三维的按钮

用VBA创建一个三维的按钮

作者:绿色风 分类: 时间:2022-08-18 浏览:86
楼主
wise
用VBA创建一个三维的按钮
具体代码如下:


  1. Sub Makebutton()
  2.     Dim shp As Shape
  3.     On Error Resume Next
  4.     With ActiveSheet
  5.         .Shapes("简单基本按钮").Delete
  6.         .Shapes("简单按钮文本").Delete
  7.     End With
  8.     On Error GoTo 100
  9.     param = Split(InputBox("输入" & vbCr & "高度, 左边, 按钮名称 , 模块名称", "简单按钮", "30, 30, 简单按钮, GetOk"), ",")
  10.     Create_Easy_Button CInt(param(0)), CInt(param(1)), Trim(param(2)), Trim(param(3))
  11. 100:
  12. End Sub

  13. Sub Create_Easy_Button(x As Integer, Y As Integer, sText As String, sMacro As String)
  14.     Dim Wdth As Long
  15.     Dim Ht As Long
  16.     Wdth = Len(sText) * 9
  17.     If Len(sText) < 5 Then
  18.         Ht = Wdth
  19.     Else
  20.         Ht = Wdth * (50 - Len(sText)) / 100
  21.     End If
  22.     With ActiveSheet.Shapes.AddShape(msoShapeRectangle, x, Y, Wdth, Ht) '添加形状类型,设置形状的属性
  23.         .Name = "简单基本按钮"
  24.         .Fill.ForeColor.RGB = RGB(200, 0, 0) '填充颜色
  25.         .Placement = xlFreeFloating
  26.         .OnAction = "触发GetOk" '每当单击形状时,运行GetOk 过程
  27.         With .Line
  28.             .ForeColor.RGB = RGB(255, 255, 255)
  29.             .Weight = 3
  30.         End With
  31.         With .Shadow '显示阴影
  32.             .Visible = True
  33.             .OffsetX = 2
  34.             .OffsetY = 2
  35.             .Transparency = 0.5
  36.             .ForeColor.RGB = RGB(10, 10, 10)
  37.         End With
  38.         With .ThreeD '显示3D形式
  39.             .BevelTopType = 3
  40.             .BevelTopDepth = 20
  41.             .BevelTopInset = 19
  42.             .ContourWidth = 0
  43.             .Depth = 2
  44.             .ExtrusionColorType = 1
  45.             .FieldOfView = 45
  46.             .LightAngle = 300
  47.             .Perspective = 0
  48.             .PresetLighting = 15
  49.             .PresetMaterial = 6
  50.         End With
  51.     End With
  52.     With ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, x - 1, (Y + Ht / 2) - 18, Wdth, 35)
  53.         .Name = "简单按钮文本"
  54.         With .TextFrame '添加文本,然后设置文本框架的边距
  55.             .MarginBottom = 0
  56.             .MarginLeft = 0
  57.             .MarginRight = 0
  58.             .MarginTop = 0
  59.             .HorizontalAlignment = xlHAlignCenter
  60.             .VerticalAlignment = xlVAlignCenter
  61.             .Characters.Text = sText
  62.             With .Characters.Font '设置文本字体属性
  63.                 .Bold = True
  64.                 .Size = 10
  65.                 .Name = "Calibri"
  66.                 .Color = RGB(255, 255, 255)
  67.                 .Shadow = True
  68.             End With
  69.         End With
  70.         .Line.Visible = False
  71.         .Fill.Visible = False
  72.         .TextEffect.PresetTextEffect = 2
  73.         .Placement = xlFreeFloating
  74.         .OnAction = sMacro
  75.     End With
  76. End Sub
  77. Sub GetOk()
  78.     MsgBox "按钮已经插入!"
  79. End Sub


简单按钮.rar
2楼
wnianzhong
挺漂亮的,学习了!

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap