来自文本input框的参数

我需要什么样的VBA代码来显示一个名为“input名字”的popup文本框,这个名字将被粘贴在三个不同的地方: Sheets("Data").SelectA15A50 Sheets("Data").Select (两个超链接,不想搞乱),第三个是Sheets("Run").Select ,这是一个button。

所有这三个地方被称为Other 1 ,我希望能够从popup的input信息来改变它们。

 Sub TestMacro() Dim Name As String Name = InputBox("Enter Name.") Range("A" & 15).Value = Name Range("A" & 50).Value = Name Sheets("Run").Select Range("A" & 1).Value = Name Sheets("Data").Select End Sub 

我想我已经为你准备了一些东西。

 Sub TestMacro() Dim Name As String Name = InputBox("Enter Name.") If StrPtr(Name) = 0& Then Exit Sub 'user cancelled out of inputbox! SetCellValue Sheets("Data"), "A15", Name SetCellValue Sheets("Data"), "A50", Name SetCellValue Sheets("Run"), "A1", Name 'Forms button can be accessed with the "Buttons" collection of "Worksheet" object: Sheets("Run").Buttons(1).Caption = Name 'assumes it's the first button in the collection 'ActiveX button can be accessed directly by its programmatic name: Sheet1.CommandButton1.Caption = Name 'assumes sheet "Run" is Sheet1 End Sub Private Sub SetCellValue(xlSheet As Worksheet, addr As String, value As Variant) xlSheet.Range(addr).Value = value End Sub