如果你有Excel任何问题,请留言或者加我们qq 24119011 让我们知道。谢谢

excel表格的基本操作-excel教程网

当前位置: 主页 > 高级教程 > vba >

Excel VBA经典应用案例(设计按钮)

时间:2014-11-21 09:47来源:excel.org.cn 作者:admin 点击:
设计按钮 Sub RunTimeButton() Adds a button at runtime Make sure access to the VBProject is allowed On Error Resume Next Set x = ActiveWorkbook.VBProject If Err 0 Then MsgBox Your security settings do not allow this macro to run., vbCriti
设计按钮
Sub RunTimeButton()
' Adds a button at runtime

' Make sure access to the VBProject is allowed
  On Error Resume Next
  Set x = ActiveWorkbook.VBProject
  If Err <> 0 Then
    MsgBox "Your security settings do not allow this macro to run.", vbCritical
    On Error GoTo 0
    Exit Sub
  End If

  Dim Butn As CommandButton
  Set Butn = UserForm1.Controls.Add("Forms.CommandButton.1")
  With Butn
    .Caption = "Added at runtime"
    .Width = 100
    .Top = 10
  End With
  UserForm1.Show
End Sub

Sub DesignTimeButton()
' Adds a button at design-time

' Make sure access to the VBProject is allowed
  On Error Resume Next
  Set x = ActiveWorkbook.VBProject
  If Err <> 0 Then
    MsgBox "Your security settings do not allow this macro to run.", vbCritical
    On Error GoTo 0
    Exit Sub
  End If

  Dim Butn As CommandButton
  Set Butn = ThisWorkbook.VBProject.VBComponents("UserForm1") _
    .Designer.Controls.Add("Forms.CommandButton.1")
  With Butn
    .Caption = "Added at design-time"
    .Width = 120
    .Top = 40
  End With
  VBA.UserForms.Add("UserForm1").Show
End Sub
(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%

------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
验证码: 点击我更换图片