通过VBA反复添加启用了宏的按钮

时间:2019-02-27 15:59:19

标签: excel vba

尝试创建一个用户可以在其中输入注释的输入框,这些注释将被输入到同一文档中,同时创建一个宏,从而启用“竖起图标”,该图标将保留一个宏,其他成员可以“竖起”这些想法他们想提升。下面的代码使按钮在同一单元格上重复自身。我需要它来应用于下一个可用单元格。

Sub VBA_Input_Idea_inputbox() 
 Dim MyInp As String
 Dim NextRow As Long

 MyInp = VBA.Interaction.InputBox("Please input idea", "LEARNING 
    REQUEST")
  If MyInp = "" Then Exit Sub
 NextRow = Cells(Rows.Count, 3).End(xlUp).Row + 1
 Range("C" & NextRow).Value = 
 Excel.WorksheetFunction.Proper(MyInp)
 Range("A" & NextRow).Select
 ActiveSheet.Buttons.Add(0.75, 145.5, 42, 24.75).Select
 Selection.OnAction = "Addcount"
  End Sub

1 个答案:

答案 0 :(得分:0)

类似这样的东西:

Sub VBA_Input_Idea_inputbox()
    Dim MyInp As String
    Dim NextRow As Range, btn

    MyInp = VBA.Interaction.InputBox("Please input idea", "LEARNING REQUEST ")
    If MyInp = "" Then Exit Sub
    With ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).EntireRow
       .Cells(3).Value = Application.Proper(MyInp)
       Set btn = ActiveSheet.Buttons.Add(.Cells(1).Left, .Cells(1).Top, _
                                         .Cells(1).Width, .Cells(1).Height)
       btn.OnAction = "Addcount"
    End With
End Sub