none
Access global.mpt from VBA RRS feed

  • שאלה

  • Hi,

    I'd like to export all modules in my global.mpt to flat text (to get some sort of version control). I've found code to use VBProject.VBComponents but it is referencing ActiveProject (which is obviously not my global.mpt file). Any ideas oder hints how to reference to the global template file? I'm runing MSP Prof 2010.

    Thanks, Stefan.

    יום שני 21 אוקטובר 2019 06:06

תשובות

  • Hi,

    does this give you a starting point?

    Sub ReadCodeFromGlobalMPT()
    Dim oVBP
    Dim oVBC
    
    Set oVBP = Application.VBE.VBProjects.Item("ProjectGlobal")
    Set oVBC = oVBP.VBComponents
    For i = 1 To oVBC.Count
        'Module Name
        Debug.Print oVBC.Item(i).Name
        'Module Code
        If oVBC.Item(i).CodeModule.CountOfLines > 0 Then
            Debug.Print oVBC.Item(i).CodeModule.Lines(1, oVBC.Item(i).CodeModule.CountOfLines)
        Else
            Debug.Print "No code lines"
        End If
    Next i
    
    End Sub

    Regards
    Barbara


    Barbara Henhapl Blog (English/German)

    • סומן כתשובה על-ידי swa72 יום שלישי 22 אוקטובר 2019 14:33
    יום שני 21 אוקטובר 2019 13:53
    מנחה דיון

כל התגובות

  • Hi,

    does this give you a starting point?

    Sub ReadCodeFromGlobalMPT()
    Dim oVBP
    Dim oVBC
    
    Set oVBP = Application.VBE.VBProjects.Item("ProjectGlobal")
    Set oVBC = oVBP.VBComponents
    For i = 1 To oVBC.Count
        'Module Name
        Debug.Print oVBC.Item(i).Name
        'Module Code
        If oVBC.Item(i).CodeModule.CountOfLines > 0 Then
            Debug.Print oVBC.Item(i).CodeModule.Lines(1, oVBC.Item(i).CodeModule.CountOfLines)
        Else
            Debug.Print "No code lines"
        End If
    Next i
    
    End Sub

    Regards
    Barbara


    Barbara Henhapl Blog (English/German)

    • סומן כתשובה על-ידי swa72 יום שלישי 22 אוקטובר 2019 14:33
    יום שני 21 אוקטובר 2019 13:53
    מנחה דיון
  • Hi Barbara,

    spot on :-) Thanks a lot.

    Here is my code to export module by module ...

    Public Sub ExportVBAComponentsGlobalMPT()
    
        Dim vbComp As Object
        Dim exportPath As String
        Dim swaPath As String
    
    On Error Resume Next
        swaPath = "D:\Data\Documents\configs\project-vba-code-svn\" + Format(Now(), "yyyy-MM-dd-hh-mm-ss")
        MkDir swaPath
    On Error GoTo EH
    
        For Each vbComp In Application.VBE.VBProjects.Item("ProjectGlobal").VBComponents
    
            exportPath = swaPath & "\" & vbComp.name
            Select Case vbComp.Type
                Case 1 ' Standard Module
                    exportPath = exportPath & ".bas"
                Case 2 ' UserForm
                    exportPath = exportPath & ".frm"
                Case 3 ' Class Module
                    exportPath = exportPath & ".cls"
                Case Else ' Anything else
                    exportPath = exportPath & ".bas"
            End Select
            
            On Error Resume Next
            vbComp.Export exportPath
            On Error GoTo EH
        Next
      
    Done:
        Exit Sub
    EH:
        DisplayError Err.Source, Err.Description, "ExportVBAComponentsGlobalMPT", Erl
    End Sub
    

    יום שלישי 22 אוקטובר 2019 14:35