+ Reply to Thread
Results 1 to 13 of 13

Adding a new sheet with command button

  1. #1
    Registered User
    Join Date
    06-13-2007
    Posts
    58

    Cool Adding a new sheet with command button

    I just stuck on the basics. I want to add a new sheet through a macro and a button in the same. I am unable to make it dynamic. it is giving me an error:

    Can anyone help me on the same:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    far simpler to have a hidden template sheet that you copy when needed.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-13-2007
    Posts
    58
    didnt get u man... how to do it??

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Just create a sheet with all the controls, formatting & formulas. Save 7 hide it then use code to create a copy when needed.

    See the Summary sheet's code here

    http://www.excel-it.com/workbook_downloads.htm

  5. #5
    Registered User
    Join Date
    06-13-2007
    Posts
    58
    Thanks for your help man. But

    1) the website link is not working
    2) Basically I need to embed the same in another macro... The original macro starts with 2 sheets... and when it starts processing it deletes all other existing sheet.. even if u manually add anything.. it creates around 8-9 sheets for processing the macro and then delete all other sheets.... Keep only the original 2 sheets and a new 1 processed sheets....

    So I cant keep anything hidden.... Thats Y i want to create another macro with above functionality...

    Is there any solution??

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The link is fine.

  7. #7
    Registered User
    Join Date
    06-13-2007
    Posts
    58
    the solution is not working... can any1 help??

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by crapmind
    the solution is not working... can any1 help??
    Spend a little time on your replies. If you bother to explain why the solution is not working then maybe you will get some help.

  9. #9
    Forum Contributor corinereyes's Avatar
    Join Date
    12-02-2003
    Location
    Philippines
    MS-Off Ver
    MS Excel 2016
    Posts
    520

    Adding a new sheet with a command button

    Hello Crapmind,

    Sub abc()
    Dim oWS1 As Worksheet
    Set oWS1 = ActiveSheet

    Sheets(oWS1).Select
    Sheets.Add
    Sheets("Sheet4").Select
    Sheets("Sheet4").Name = "Tol"

    ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
    , DisplayAsIcon:=False, Left:=345.75, Top:=11.25, Width:=165.75, _
    Height:=40.5).Select

    Set vObj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Left:=345.75, Top:=11.25, _
    Width:=165.75, Height:=40.5)

    Set CmdBtn = vObj.Object 'This is a read only property

    CmdBtn.Caption = "Misc Info"

    End Sub

    I've checked your code and its working fine. From your code ---> Sheets(oWS1).Select just put " " on the sheet name --> Sheets("oWS1").Select

    Hope this helps you.

    corine
    Corine

  10. #10
    Registered User
    Join Date
    01-16-2007
    Location
    Near the box
    Posts
    58
    I think this kind of the problem has been kicked around recently. So check the threads below:

    http://www.excelforum.com/showthread.php?t=609667
    http://www.excelforum.com/showthread...76#post1812176
    ? ? ? I like the way how Excel can access system API. Really cool ! ? ? ?

  11. #11
    Registered User
    Join Date
    06-13-2007
    Posts
    58
    1st to royUK

    ur link is still not working.... If you wud have read my problem properly then u wud have understand y the solution is not working.

    2nd to corinereyes

    Thanks a lot buddy for spending valuable time on this. There is a basic problem in my code. There will not be any Sheet4 or something like that... So macro gives a run-time error whenever it doesnt find Sheet4.. thats y i want to make it dynamic... Can this problem be resolved?? pls help

    3rd to bettatronic

    I am checking out the threads... Still need to analyse how to incorporate the same into my macro... thanks a lot buddy.. anyways check out my post if u can help me on the same..

    Thanks

    crapmind

  12. #12
    Forum Contributor corinereyes's Avatar
    Join Date
    12-02-2003
    Location
    Philippines
    MS-Off Ver
    MS Excel 2016
    Posts
    520
    Hi Crapmind,

    Try this code.

    Private Sub CommandButton1_Click()

    Set NewSheet = Sheets.Add(Type:=xlWorksheet)
    NewSheet.Name = "Tol"
    With NewSheet
    Set vObj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Left:=345.75, Top:=11.25, _
    Width:=165.75, Height:=40.5)
    Set CmdBtn = vObj.Object 'This is a read only property
    CmdBtn.Caption = "Misc Info"
    End With


    End Sub
    i have put the code in a command button. See the example file i've attached.

    Hope this helps you.
    Attached Files Attached Files
    Last edited by corinereyes; 08-13-2007 at 02:34 AM.

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by crapmind
    1st to royUK

    ur link is still not working.... If you wud have read my problem properly then u wud have understand y the solution is not working.

    crapmind
    The link does work, and if you can't be bothered to explain why creating a hidden template sheet with the button required is not going to work then I won't waste any more time with your problem!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1