Best way to source control VBA code.

Anonymous
2012-09-18T23:19:37+00:00

Hi,

Was wondering if people have encountered a situation where they want to source control Excel VBA.

We have a team working on complex Macros. I want to be able to track code changes of VBA code of Excel Macros. Unfortunately xla's files are binaries and its not recommend to put binaries in TFS. (We are using TFS as our source control tool.) Instead of writing code to extract each Excel objects that has code, put in a text file and save to TFS, is there a better way. I'm all ears. If my options is the only one, then is thre code laying around that I could use for this extraction! 

thanks.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2012-09-19T04:23:38+00:00

    hi thanks for that.  I thank the orginal coder.  I made a minor adjustment. works perfert for forms and class modules.

    Sub SaveVBACode()

    'This code Exports all VBA modules

    Dim i As Integer

    Dim mName As String

    Dim Fname As String

        With ThisWorkbook

            For i = 1 To .VBProject.VBComponents.Count

                If .VBProject.VBComponents(i).CodeModule.CountOfLines > 0 Then

                    mName = .VBProject.VBComponents(i%).CodeModule.name

                     Fname = .path & "" & mName & ".txt"

                    .VBProject.VBComponents(mName).Export Fname

                End If

            Next i

        End With

    End Sub

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Kevin Jones 7,225 Reputation points Volunteer Moderator
    2012-09-18T23:54:52+00:00

    You have the right idea.

    Here is a discussion and some sample code to do the exporting and importing:

    http://stackoverflow.com/questions/131605/best-way-to-do-version-control-for-ms-excel

    Kevin

    0 comments No comments