Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 29

Thread: Compare 2 VBA Projects (code)

  1. #1
    VBAX Tutor
    Joined
    Mar 2010
    Posts
    287
    Location

    Question Compare 2 VBA Projects (code)

    I have 2 VBA projects that have subtle coding differences (but this is creating a real impact on the end result).

    Visual Source Safe is in use but both versions were updated offline without using checkout and so I now need a macro to compare both .xls files and show the differences in the code on a line by line basis - so that I can stitch together the relevant changes from each into a single file.

    Any help appreciated as it is going to be a mammoth task if completed manually...

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Export the modules as text files, and then use a text file comparison application to compare them.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    BTW, what is the point of having SourceSafe if you allow modifying offline?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Tutor
    Joined
    Mar 2010
    Posts
    287
    Location
    I am not in control of this. I just inherited the issue.

    What text comparison software would you suggest?

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I use TextPad. It is a text editor (a very good one), but it has a compare function as well. It is shareware, but you can download it free and do what you need.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Tutor
    Joined
    Mar 2010
    Posts
    287
    Location

    Exclamation

    Found a freebie - ~545kb and has a nice simple interface

    http://www.mediafire.com/?csss3yal9caxlep

    TestDiff

    Thanks again - just a shame there is no VBA module / userform for this so I could run it as an addin in Excel (and save back to modules without the text export step).

    When I become a VBA genuis I'll put one together...

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Have a look at WinMerge, a free utility for comparing vba code. Or failing that its possible to copy the code into Word and run text compare from there
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  8. #8
    Quote Originally Posted by theta
    I am not in control of this. I just inherited the issue.

    What text comparison software would you suggest?
    Suggestion:
    www.jkp-ads.com/download.asp#exportvbaproject
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  9. #9
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    You could also save both projects as separate Word files, then use Word's Compare/Combine tools for the comparison.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  10. #10
    macropod: you'd still have to "save" each code module manually, or do you know a fast way to export everything in one go?
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  11. #11
    VBAX Tutor
    Joined
    Mar 2010
    Posts
    287
    Location
    Quote Originally Posted by Jan Karel Pieterse
    macropod: you'd still have to "save" each code module manually, or do you know a fast way to export everything in one go?
    If you look at the functionality of the file I uploaded - it would be amazing to have that functionality as an addin + userform. Then you could open up "Original.xls" and "Adjusted.xls" and compare the two projects in that way.

    I would happily work on a project to make this a reality...

  12. #12
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by Jan Karel Pieterse
    macropod: you'd still have to "save" each code module manually, or do you know a fast way to export everything in one go?
    Well, one could export each module using vba, but for a one-off project that hardly seems worth the effort.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  13. #13
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Who says it is a one-off? If they allow their source control to be ignored, they probably do this a lot
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  14. #14
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Maybe, or maybe they'll learn to use SourceSafe the way it's meant to be used. Otherwise they may as well ditch it.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  15. #15
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    Quote Originally Posted by Jan Karel Pieterse
    macropod: you'd still have to "save" each code module manually, or do you know a fast way to export everything in one go?

    http://www.appspro.com/Utilities/CodeCleaner.htm

    Rob Bovey's Code Cleaner has the option to export all modules (UF, Cls, Std) with one click

    Also does other amazing things

    Paul

  16. #16
    Paul, macropod: the tool I referred to exports the entire VBA project into one single textfile, making comparing a breeze.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  17. #17
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi JKP,

    I take it you're referring to ExamDiff. While not for a moment suggesting Word is a better tool, I was simply pointing the OP to software they probably already have. Word, of course, won't compare userform differences, so the OP may need something more adept than either Word or ExamDiff (the web page doesn't seem to suggest any capabilities in that regard).
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  18. #18
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No, he is referring to the stage before that comparison, and is suggesting his ExportVBAProject tool www.jkp-ads.com/download.asp#exportvbaproject, which creates a single text file which mitigates the comparison process whichever tool is used for that comparison.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  19. #19
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    OK, but as I see it the crux of the issue is how to do the comparison, not how to export the code. Whether having it all in a single file makes the comparison any easier is debatable. After all, it's pretty easy to confirm that pairs of files have the same content. In a large project with multiple modules, a module-by-module comparison would, arguably, make it easier to find which modules had been changed, and where, than trying to compare the lot as a single file.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  20. #20
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Beg to differ on both points.

    It is a hollow victory if the comparison works easily but it takes a lot of effort to get the data to the compare stage, and vice versa. When you have a process, each step is important and should be optimised.

    I would rather compare 1 file that 35 any day of the week, even in a semi-automated process. Any comparison tool worth anything will re-align after it finds differences. Jan
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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