Question : Add a button to an Excel Spreadsheet

I have written a reports engine that creates a nicely formatted report pack as an excel spreadsheet.  It creates the spreadsheet from scratch.  

What I now need to do is add a few buttons onto the summary sheet and put some code behind the buttons.  I have code I want to add to the buttons but I am having difficulty actually adding it.

Can anyone help?

Answer : Add a button to an Excel Spreadsheet

Hello sbiddle

Just a bit late, but with more "feature" ;)
Creates a worksheet, with a macro and  a button launching it...

    ' XL is an open Excel Application...
   
    With XL.Workbooks.Add
       
        With .VBProject.VBComponents.Add(1)
            .CodeModule.AddFromString _
                  "Sub Hello()" & vbCrLf _
                & "    MsgBox ""hello world!""" & vbCrLf _
                & "End Sub"
        End With
       
        With .Worksheets(1).Buttons.Add(50, 50, 50, 30)
            .OnAction = "Hello"
            .Caption = "Hello!"
        End With
        .Saved = True
       
    End With


Have Fun!

(°v°)
Random Solutions  
 
programming4us programming4us