Results 1 to 7 of 7

Thread: Comparing External VBA project files.

  1. #1

    Thread Starter
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Comparing External VBA project files.

    I have a great number of external VBA project files. (Backup-ed versions)
    I need to compare them and get a listing of the differences in code.
    In the short term the reason is to locate a hidden bug that I cannot track down.

    Perhaps a printout of Form, Module, Sub Routine, Function name where the differences occur.

    Before I tackle writing my own tool for the job I was wondering if I'm not reinventing the wheel.

    Failing an existing tool where would one start? I thought I read something about them being zipped data.

    The good news is going forward I intend to turn over a new leaf in
    keeping track of changes and documenting for the future.
    Last edited by Gruff; Jan 30th, 2015 at 10:32 AM.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  2. #2
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Comparing External VBA project files.

    This is not an endorsement, but just the result of a search on "VBA Diff".

    http://www.vbadiff.com/

  3. #3

    Thread Starter
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Comparing External VBA project files.

    Thanks T,

    I will look into it.
    It may be problematical though as the VBA project I am trying to dump uses VBA 7 64 bit.
    I cannot find VBIDE.dll or its source on the 64 bit PC. The VBA project files are for Inventor and Autocad.

    There is a VBAProjects under this application that I can drill down into but it doesn't seem to go down to the code level. If also causes a crash if I try to loop through everything.

    ThisApplication.VBAProjects Meh.
    ---

    This just in. I Finally found the path to:
    Microsoft Visual Basic for Applications Extensibility 5.3

    It was under C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VB6\VBE6EXT.OLB

    So... Some progress.
    Last edited by Gruff; Jan 30th, 2015 at 03:36 PM.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  4. #4

    Thread Starter
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Comparing External VBA project files.

    Got it I think.
    Now that VBE can be referenced I can initialize the VBE codemodule class from the inventorVBAComponent Class.

    Dim oCodeModule As CodeModule '<--- CodeModule is defined in VBE
    Set oCodeModule = oModule.VBComponent.CodeModule

    BTW I ended up writing the whole thing in Inventors VBA.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  5. #5
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Comparing External VBA project files.

    Quote Originally Posted by Gruff View Post
    Got it I think.
    Now that VBE can be referenced I can initialize the VBE codemodule class from the inventorVBAComponent Class.

    Dim oCodeModule As CodeModule '<--- CodeModule is defined in VBE
    Set oCodeModule = oModule.VBComponent.CodeModule

    BTW I ended up writing the whole thing in Inventors VBA.
    I'm glad you got figured out. The last time I did any ACAD programming was the early 90's in AutoLisp and I doubt I would be even able to understand any of that any more.

  6. #6

    Thread Starter
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Comparing External VBA project files.

    Here is the final generic VBA tool I came up with.
    Feel free to use it if necessary.
    With MS Office docs you do not need to go to these lengths as VBA is saved inside the Office docs.

    With Inventor and Autocad they are External files.

    VBA code follows
    Code:
    Option Explicit
    
    Public Sub DumpAllVbaProjectCode()
      ' This utility was written for 64 bit Inventor 2015. Untested with 32 bit.
      ' Make sure to reference VBE (Microsoft Visual Basic for Applications Extensibility 5.3
      
      ' You may have to browse to the file containing the reference:
      ' C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VB6\VBE6EXT.OLB
    
      Const vbext_ct_StdModule = 1
      Const vbext_ct_ClassModule = 2
      Const vbext_ct_MSForm = 3
      Const vbext_ct_Document = 100
      
      Dim oModule As InventorVBAComponent
      Dim sOut As String
      
      sOut = ""
      For Each oModule In ThisApplication.VBAProjects(1).InventorVBAComponents
        With oModule.VBComponent
          If .Type >= vbext_ct_StdModule And .Type <= vbext_ct_Document Then
            
            Dim PadLine As String
            If sOut = "" Then
              PadLine = ""
            Else
              PadLine = vbCrLf
            End If
            
            sOut = sOut & PadLine & "' \\\ " & oModule.Name & " ///" & vbCrLf
            
            Dim oCodeModule As CodeModule
            Set oCodeModule = oModule.VBComponent.CodeModule
            
            sOut = sOut & CleanString(oCodeModule.Lines(1, oCodeModule.CountOfLines)) & vbCrLf
          End If
        End With
      Next
    
      Open "C:\VBA_Dump.txt" For Output As #1
        Print #1, sOut
      Close #1
    
      MsgBox "VBA Project Dumped"
    End Sub
    
    Public Function CleanString(STR As String) As String
      ' Formalizes the output so it may be compared with other versions of the project.
      Dim sLines() As String
      Dim sOut As String
      Dim i As Integer
      
      ' remove tabs
      STR = Replace(STR, vbTab, "")
    
      sLines = Split(STR, vbCrLf)
      For i = 0 To UBound(sLines) - 1
        sLines(i) = RTrim(sLines(i))
        If Not (sLines(i) = RTrim(sLines(i + 1)) And sLines(i) = "") Then
          ' construct new string
          sOut = sOut & sLines(i) & vbCrLf
        End If
      Next i
    
      Do
        ' Clean up trailing newlines
        If Right$(sOut, 2) = vbCrLf Then
          sOut = Left$(sOut, Len(sOut) - 2)
        End If
      Loop Until Right$(sOut, 2) <> vbCrLf
      
      CleanString = Trim(sOut)
    End Function
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  7. #7
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Comparing External VBA project files.

    Gruff,

    I totally spaced out this reference that you may find useful. It is geared towards VBA under Excel, but the basic concepts should apply to all VBA.

    Programming The VBA Editor

Posting Permissions

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



Click Here to Expand Forum to Full Width