+ Reply to Thread
Results 1 to 6 of 6

Add code automatically to a sheet as it is inserted

  1. #1
    Registered User
    Join Date
    08-16-2019
    Location
    Lincoln, England
    MS-Off Ver
    2016
    Posts
    1

    Add code automatically to a sheet as it is inserted

    Hi all,

    My current sheet has a macro that uses a userform to add a new named sheet (eg. 'Coats'). Is there any code i can use in my userform module to then add some code automatically to the coats worksheet module as it is inserted?

    The code i'm looking to add to the worksheet is:

    Private Sub AddNewProduct_Click()
    form_AddNewProduct.Show
    End Sub

    Many thanks in advance

  2. #2
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Add code automatically to a sheet as it is inserted

    untested
    Please Login or Register  to view this content.
    you will need to reference Microsoft Visual Basic for Applications Extensibility 5.3
    Attached Images Attached Images
    Last edited by nigelog; 08-16-2019 at 06:49 AM.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add code automatically to a sheet as it is inserted

    Christian

    Is AddNewProduct a button?

    If it is what type and where is it located?


    nigelog

    CreateEventProc is for creating event procedures in worksheets and workbooks, there is no AddNewProduct_Click event for either.
    If posting code please use code tags, see here.

  4. #4
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Add code automatically to a sheet as it is inserted

    @ Norie
    Code I used recently for a right click event on a excel output
    I had spotted that but had not a chance to assign to find a way to write to an ordinary Sub routine. Too many distractions today unfortunately...

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi !

    As the easy way is to copy a template worksheet which has already the code but yes it's too obvious …

  6. #6
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Add code automatically to a sheet as it is inserted

    as its in same workbook
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 01-01-2015, 09:38 PM
  2. Replies: 7
    Last Post: 07-29-2014, 11:10 AM
  3. [SOLVED] Code locks cells when inserted in sheet module but returns error in standard module
    By yoda66 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2014, 07:39 AM
  4. [SOLVED] Code to transfer latest entry from sheet 'Account' to sheet 'Summary' automatically
    By mukeshbaviskar in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-30-2014, 08:56 PM
  5. Need values to be automatically inserted
    By Francoise in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 09-09-2011, 07:42 PM
  6. How to have rows automatically inserted with the tab key
    By friend11_6 in forum Excel General
    Replies: 0
    Last Post: 07-19-2009, 09:02 PM
  7. Replies: 1
    Last Post: 07-20-2008, 02:22 PM

Tags for this Thread

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