Consulting

Results 1 to 3 of 3

Thread: Solved: Delete Command Button

  1. #1
    VBAX Regular
    Joined
    Nov 2007
    Posts
    28
    Location

    Solved: Delete Command Button

    Hi there! Just a quick check. I put a Command Button in an Excel Sheet, "Monthly Report", in which it will copy this sheet along with another sheet, "Variables", and save it in a new workbook.

    However, the Command Button will be copied as well. So is there anyway in VBA that I can delete the command button from the new workbook?

    here are the codes from the Main workbook which have the command Button to generate that report

    [vba]
    Sub GenReport()
    Dim DistiName As String
    Dim filename As String
    Dim MyMonth As Variant

    Application.ScreenUpdating = False
    MyMonth = Application.Proper(MonthName(Month(Date)))
    Sheets("report").Activate
    DistiName = Sheet23.Cells(5, 1)
    Sheets(Array("Variables", "Report")).Copy
    Sheets("Variables").Visible = xlVeryHidden
    filename = ThisWorkbook.Path & "\" & DistiName & "-" & MyMonth & ".xls"
    Application.CalculateFullRebuild
    DeleteLinks_Selection
    ActiveWorkbook.Sheets("Report").Range("A5").Validation.Delete
    CommandButton1.Delete
    ActiveWorkbook.SaveAs filename
    Application.ScreenUpdating = True
    End Sub
    [/vba]

    However when the code reach the line "commandbutton1.delete", they prompt me an error , "Run time '424' Object Required". Anybody willing to help?



    regards
    artds

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Activesheet.Buttons("Button 1").Delete
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Nov 2007
    Posts
    28
    Location

    Lightbulb

    Hi xld! Thanks for your quick response!
    Initially, i tried using your suggestion, but it didn't work. VBA prompt me an error, but from that point, I experimented on some other codes.

    so heres the code that works for me,

    [vba]
    ActiveSheet.Shapes("CommandButton1").Delete
    [/vba]
    where "CommandButton1" is the name of that command button. Thanks xld for your direction.


    regards
    artds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •