+ Reply to Thread
Results 1 to 3 of 3

Extracting Comments

Hybrid View

  1. #1
    Registered User
    Join Date
    01-17-2011
    Location
    Kent
    MS-Off Ver
    Excel 2007
    Posts
    34

    Extracting Comments

    Hey guys,

    does any one know of a piece of code i can use to copy the comments out of a macro (i.e. all the lines starting with ') and maybe past them into a seperate sheet? i've seen it done in SQL before, but i'm not sure if it's possible here or not...

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Extracting Comments

    Something like this.

    Sub ExtractComments()
    '
    ' This sub will extract
    ' comments from code
    '
        Dim strCode As String
        Dim strComments As String
        Dim lngRow As Long
        Dim vntLine As Variant
            
        ' access active project
        With Application.VBE.ActiveVBProject.VBComponents.Item("Module1").CodeModule
            ' grab all lines of code
            strCode = .Lines(1, .CountOfLines)
        End With
        
        For Each vntLine In Split(strCode, vbCrLf)
            ' locate comment line
            If Left(Trim(vntLine), 1) = "'" Then
                lngRow = lngRow + 1
                ' output to worksheet
                ActiveSheet.Cells(lngRow, 1) = vntLine
            End If
        Next
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Extracting Comments

    Wow Thats great Andy, NEver knew that was possible..!

+ 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