1

我需要什么 VBA 代码来显示“输入名称”的弹出文本框,以便将该名称粘贴到三个不同的位置:Sheets("Data").SelectinA15A50(我不想弄乱的两个超链接),以及第三个地方是Sheets("Run").Select,这是一个按钮。

这三个地方都被调用了Other 1,我希望能够使用弹出窗口中的输入信息来更改它们。

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
4

1 回答 1

1

我想我有东西给你。

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
于 2013-10-02T01:37:32.370 回答