+ Reply to Thread
Results 1 to 4 of 4

Generate a Private Sub from a Macro?

  1. #1
    Registered User
    Join Date
    12-26-2019
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    68

    Generate a Private Sub from a Macro?

    Hi community,

    I have a macro that generates a report, the code is pasted into a module and I just run it.
    I have another code which is a private sub, that highlights the currently selected cell to help me focus.
    This code is pasted into the worksheet editor and not in module.
    I was wondering if there is a code that I just paste in module which then generates the code in worksheet automatically?
    Would love to avoid pasting that highlight cell code every time I am doing the report which is twice a week.
    Any help from an Excel genius would be greatly appreciated.

    Here is the highlight cell code by the way.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit
    Posts
    451

    Re: Generate a Private Sub from a Macro?

    If you use event 'Workbook_SheetSelectionChange' instead of 'Worksheet_SelectionChange' and place the macro in the module ThisWorkbook it would be available for all sheets. If highlighting isn't necessary in every sheet just add the appropriate ecception to the macro (ex. If Sh.Name = "Sheet2" Then Exit Sub).
    Please Login or Register  to view this content.
    Last edited by rollis13; 04-11-2021 at 04:41 AM.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    2013 on Win10 (desktop), 2007 on Win10 (notebook)
    Posts
    8,096

    Re: Generate a Private Sub from a Macro?

    Hi frankytheman,

    I assumed the workbook is closed, so it`s path and name as well as extension need to be given as well as the Codename of the sheet from the VBE (not the visible name on the tab):

    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    12-26-2019
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    68

    Re: Generate a Private Sub from a Macro?

    Hi Holger, this is exactly what I was looking for. Amazing! You are a genius. Sauber! Vielen lieben Dank! :-)

+ 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. Combine Private Sub and Private Function VBA code
    By thanhthinh1234 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-25-2018, 06:16 AM
  2. Call Macro from Private Sub
    By mgolda87 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2016, 12:32 PM
  3. How to delete a private sub macro?
    By MetroBOS in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-12-2015, 02:21 PM
  4. Looking to run a Private Sub Macro
    By potter185 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-24-2014, 07:31 AM
  5. [SOLVED] how to run macro( Private sub)
    By var in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2012, 12:18 AM
  6. running a private sub macro
    By NALDO in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-24-2012, 06:44 PM
  7. Calling a private macro
    By Nick Smith in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-08-2006, 09:20 AM

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