Consulting

Results 1 to 11 of 11

Thread: View Active Worksheet - Code Module - VBE Code Pane

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    View Active Worksheet - Code Module - VBE Code Pane

    folks,

    good day

    any one know how i can view the code in the worksheet code moddule

    I want to do it programatically


    I want to get to the view code in active sheet

    Sub ViewActiveSheetCodeModule()
    
    Application.VBE.ActiveCodePane.ActiveSheet.Show      ' < Active sheet code module eg sheet1, or Sheet2 etc
    
    VBE.ActiveSheet.MainWindow.Visible = True
    
    End Sub
    
    macro recorder only gave this when i did right click  > view code
    
    Sub Macro2()
    '
    ' Macro2 Macro
    
    '
        Sheets("Sheet2").Select
    End Sub


    Sheet > Right click > View Code


    I would like to have a keyboard shortuct that can do this, i hate having to right click all the time

    I looked everywhere to find this but not yet
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Alt + F11
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Hello M,

    when i go to another worksheet lets say "Sheet2"

    ALT + F11

    goes to the last active worksheet code

    is it a bug in excel

    If I am on Sheet2, thats my active worksheet now

    It should now right click > View Code to sheet 2
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    My code is normally in Standard modules. My Sheet modules only contain the Events to call Subs.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    I normally put them in worksheet code Modules as sometimes i move the sheet and no code goes with it

    messy people like me need lots of "coding personal space"

    i hate the thought of all that real estate going to waste

    my normal modules - umm well i try to keep them organised but they always go missing

    I'm intrigued though how to get to the worksheet code module - i suppose i could do

    'application goto somehow

    i'll do some testing
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  6. #6
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello DJ,

    Spoiler Alert!

    Sub ShowSheetCode()
    
    
        Dim VBproj  As Object
        Dim VBcomp  As Object
        
            Set VBproj = Application.VBE.ActiveVBProject
            Set VBcomp = VBproj.VBComponents(ActiveSheet.CodeName)
            
            VBcomp.CodeModule.CodePane.Show
            
    End Sub
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you go to a specific macro in the sheet module? I can use
    Application.GoTo "Macro1"
    if it's in a standard module, but not in a Sheet Module.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Hello Leith,

    nice to see you.

    you got it in one shot.

    This is what i was imagining.

    1 click job - does it perfect.


    The problem is when I right click on a worksheet sometimes theres 4 or 5 of them so i do right click the wrong worksheet and go to the wrong code.

    So then I have to come out of it make another click then go to the right sheet then right click and before you know it well I'm in Timbuktu somewhere.

    and sometimes i start doing another job and an hour later i wonder what im doing on that worksheet
    alas excel adventures im a danger to myself.

    I just want to do a job I hate having to jump through hoops to do something, thanks Excel.


    I'm grateful you pro folks can understand what I'm saying because many a time I read my thread back and it doesn't make a word of sense to me

    Thanks M, that code yesterday has put into permanent retirement the concatenation and substitute formula for good i hope,

    it works better because i can add more to the code in the array - instead of the formula, which used to get messed up.

    Well they shouldnt be so hard on the newbie folk who have to work hard to make a formula work.
    Shoud have paid attention in school, well mind you we didnt have excel back then


    That's the nice thing about code occasionally you can decipher the meaning from the little snippets that I can muster up together, albeit very badly presented.

    I will make a keyboard shortcut for this "new shiny toy" to add to my collection.


    Well it's a nice Friday I hope everyone will have a great weekend and cheers to everyone
    Leith and M
    and forum


    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Put this in ThisWorkbook module then go the relevant code pane by double-clicking any blank cell
    Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
        Dim VBproj  As Object
        Dim VBcomp  As Object
         
        Cancel = True
        If Target = "" Then
        Set VBproj = Application.VBE.ActiveVBProject
        Set VBcomp = VBproj.VBComponents(Sh.CodeName)
         
        VBcomp.CodeModule.CodePane.Show
         End If
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    @MD,

    Thanks for your help!

    Ta gey muckle fur helping!

    Tapadh leat airson do chuideachadh!

    Alba gu brath!
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  11. #11
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Thank you M,
    thats another bonus.

    On my Keyboard I can press the dedicated key that is ACCESIBILITY it makes a double click for me.

    So i can just press that keyboard key and voila it will go there.


    I know i have a peculiar way of doing things, but the reason i put code in worksheets is becuase people keep moving my sheets and modules
    then i can never find the code again well takes me a while to jigsaw it back to gether

    and life tis too short for all this excel drama

    thanks again

    Good Evening
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


Posting Permissions

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