Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2002 - Macro Command Question

Status
Not open for further replies.

csmith10

Technical User
Joined
Dec 11, 2002
Messages
10
Location
US
Listed below is a section of the macro I'm trying to create. This section creates a Forms Button assigned with the macro called "Import". The problem I'm having is that the default text, in this case "Button 17", is displayed on the button after the macro runs. I can't get the text to change to read "Import". The result is that every time I have my primary macro run, the name on the button changes in increments of 1 (example: the next time I run the macro, the button will be labelled Button 18, etc.).

My question is, what do I need to change in order to rename the button so it displays something other than "Button ##) on the spreadsheet after it has been created? It seems as if the Record Macro function pauses once I begin editing the Button Object, so the easy way isn't working for me.



ActiveSheet.Buttons.Add(138, 171, 252.75, 123).Select
Selection.OnAction = "Import"
ActiveSheet.Shapes("Button 17").Select
Selection.Characters.Text = "Import"
With Selection.Characters(Start:=1, Length:=10).Font
.Name = "times new roman"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("A1").Select
 
Try
Code:
    ActiveSheet.Buttons.Add(138, 171, 252.75, 123).Select
    With Selection
        .Name = "ButtonX"
        .OnAction = "Import"
        .Characters.Text = "Import"
        With .Characters(Start:=1, Length:=10).Font
            .Name = "times new roman"
            .FontStyle = "Regular"
            .Size = 15
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
    End With
Just replace ButtonX with whatever name you fancy.

A.C.
 
Worked like a charm!

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top