Rubberduck: Strange source control behavior

Created on 17 Dec 2016  路  8Comments  路  Source: rubberduck-vba/Rubberduck

When I tried to start up a new repos for an existing project I ran into some issues.

First when creating a new repository using the Rubberduck guide, I got an error. But this was not in an empty project (the guide doesn't tell, but the Rubberduck manage menu says so). Then what happens in the project is that all my forms disappeared and a list of 'user forms' appeared:

rubberducksourcecontrolerror

So, is it possible to start up a repository for an existing project. I did manage to upload all my source files, but I couldn't use the Rubberduck source control anymore because the dummy user forms kept popping up and my normal form would disappear.

bug critical feature-source-control

Most helpful comment

It would be helpful if Rubberduck would offer a simple 'export all' option, to export all code Excel VBA code. That would allow you to maintain a folder as a git repository. I prefer to use git command line anyway, and I think most git users do?

All 8 comments

P.s. This is my Rubberduck trace log up til now (including Excel crash when closing app and source control issue), see attachment.
RubberduckLog.txt

Sorry closed it by accident

馃槰 wah, I knew we had a couple of issues with source control integration and user forms, but this is beyond everything I've seen so far. "Strange" seems a bit of an understatement...

It would be helpful if Rubberduck would offer a simple 'export all' option, to export all code Excel VBA code. That would allow you to maintain a folder as a git repository. I prefer to use git command line anyway, and I think most git users do?

Actually exporting all code (and formulas) to a designated source control directory is super easy using this vba code:

Option Explicit

' Exports all vba source code and
' formulas in sheets to source tree
' to facilitate source control
Public Sub ExportForSourceControl()

    Dim strPath As String

    strPath = ModGlobal.GetAfsprakenProgramFilePath & "\src\"

    ExportFormulas
    ExportVbaCode

    MsgBox "All code and formulas has been exported to: " & strPath

End Sub

Public Sub ExportFormulas()

    Dim shtSheet As Worksheet
    Dim objCell As Range
    Dim strText, strPath As String

    strPath = ModGlobal.GetAfsprakenProgramFilePath() & "\src\sheet\"

    For Each shtSheet In ActiveWorkbook.Sheets

        strText = ""

        shtSheet.Unprotect ModGlobal.CONST_PASSWORD

        For Each objCell In shtSheet.Range("A1:AX200")

            If objCell.HasFormula Then
                strText = strText & objCell.AddressLocal & ": " & vbTab & objCell.Formula & vbNewLine
            End If

        Next

        If strText <> vbNullString Then ModFile.WriteToFile strPath & shtSheet.Name & ".txt", strText

        shtSheet.Protect ModGlobal.CONST_PASSWORD

    Next shtSheet

End Sub

Public Sub ExportVbaCode()

    Dim vbcItem As VBComponent
    Dim strFile As String
    Dim strPath As String

    strPath = ModGlobal.GetAfsprakenProgramFilePath()

    For Each vbcItem In ActiveWorkbook.VBProject.VBComponents
        strFile = GetComponentFileName(vbcItem)
        vbcItem.Export (strPath & "\src\" & strFile)
    Next

End Sub

Public Function GetComponentFileName(vbcComp As VBComponent) As String

        Dim strExt As String
        Dim strPath As String

        Select Case vbcComp.Type

        Case vbext_ComponentType.vbext_ct_ClassModule
            strPath = "class"
            strExt = ".cls"
        Case vbext_ComponentType.vbext_ct_Document
            strPath = "document"
            strExt = ".doccls"
        Case vbext_ComponentType.vbext_ct_MSForm
            strPath = "form"
            strExt = ".frm"
        Case vbext_ComponentType.vbext_ct_StdModule
            strPath = "module"
            strExt = ".bas"
        Case Else
            Err.Raise 17, "GetComponentFileName", "ComponentType not supported: " & vbext_ComponentType.vbext_ct_ActiveXDesigner
        End Select

        GetComponentFileName = strPath & "\" & vbcComp.Name & strExt

End Function

The only thing is that, for now, there is no host-specific code (RD runs in all VBA hosts), and we've yet to figure out a cleanly extensible way to handle each host's specifics (e.g. worksheets in Excel, DDL scripts for table & query defs in Access, [macro-assigned] in-document shapes, etc), not to mention .frx and user form controls; what works fine for one use case is not enough for another - exporting everything that can be in a VBA project is no simple endeavor. And then there's reimporting everything, and dealing with VBE bugs and glitches (e.g. that extra empty line it inserts when importing a user form, which messes up the diffs).

That said I agree, we need an "export all" command; the SC panel's "refresh" does that, but it also does other things (syncing the in-VBE code with the file system sources, namely), and that would definitely benefit being split up.

I get that, but being able to split up your source files makes things more readable. See: https://github.com/halcwb/AfsprakenProgramma.

P.s. As a sort of a feature request. I now also export formulas and names to be able to track changes. As I am including the original Excel file in source control, it makes it very easy to revert to a specific commit. See above for my repository as an example.

Was this page helpful?
0 / 5 - 0 ratings