Menu

#123 Using winmerge 2.14.0.0 in VBA code

open
nobody
None
5
2020-04-30
2020-04-29
No

Hello,

First, I'm french so, excuse me for my english. I want to compare 2 text files with an Excel workbook. Winmerge is openning but I've always a message in the "Select Files or Folders" window : Both paths are invalid !
I've tried many things (without space in folder name, with double quotes fort spaces,....) but I don't understand where it can come from. Please, I need help !


My Windows version : 10 Enterprise
My EXCEL version : Office Professionel Plus 2016
My WinMerge version : 2.14.0.0


Values of variables in run context :
ArgsWinMerge = " /u /s /dl "Reference" /dr "Client""

LeftStringWinmerge = ""C:\Dossiers\Migrations eTpta\92001702 (Mon client test 92001072)\PERS20200401185958\ref\com\acx.bat""

RightStringWinmerge = ""C:\Dossiers\Migrations eTpta\92001702 (Mon client test 92001072)\PERS20200401185958\solution\com\acx.bat""

StringCommand = ""C:\Program Files (x86)\WinMerge\WinMergeU.exe" /u /s /dl "Reference" /dr "Client" "C:\Dossiers\Migrations eTpta\92001702 (Mon client test 92001072)\PERS20200401185958\ref\com\acx.bat" "C:\Dossiers\Migrations eTpta\92001702 (Mon client test 92001072)\PERS20200401185958\solution\com\acx.bat""

My VBA code :
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim LeftStringWinmerge As String
Dim RightStringWinmerge As String
Dim ArgsWinMerge As String
Dim StringCommand As String
Dim ApplicationWinMerge As Object
Dim ErrReturnCode As Integer

On Error Resume Next

'== Paths
Set wkb = ThisWorkbook
wkbPath = Left(wkb.Path, InStrRev(wkb.Path, "\") - 1) 'wkb.Path
CliName = ThisWorkbook.Sheets("Chiffrage").Range("C2") & " " & ThisWorkbook.Sheets("Chiffrage").Range("C3")
ProjectCode = ThisWorkbook.Sheets("Chiffrage").Range("C4")
LocalPathRef = wkbPath & "\" & CliName & "\" & ProjectCode & "\ref\"
LocalPathSolution = wkbPath & "\" & CliName & "\" & ProjectCode & "\solution\"
LocalPathRefCom = LocalPathRef & "com\"
LocalPathCliCom = LocalPathSolution & "com\"

'== Is WinMerge exists ?
If FichierExiste("C:\Program Files (x86)\WinMerge\WinMergeU.exe") = True Then
    ArgsWinMerge = " /u /s /dl " & Chr(34) & "Reference" & " /dr " & Chr(34) & "Client" & Chr(34)
    Set ApplicationWinMerge = CreateObject("WScript.shell")

    '== Open winmerge on double-clic cell
    If Target.Row > 1 And Target.Column = 4 Or Target.Column = 8 Then
        If ActiveCell.Offset(0, -3).Value2 <> "" Then
            If ActiveCell.Offset(0, -1).Value2 = "CLIDIFF" Then
                Select Case ActiveCell.Offset(0, -2).Value2
                    Case "Batch"
                        LeftStringWinmerge = Chr(34) & LocalPathRefCom & ActiveCell.Value & Chr(34)
                        RightStringWinmerge = Chr(34) & LocalPathCliCom & ActiveCell.Value & Chr(34)
                        StringCommand = Chr(34) & "C:\Program Files (x86)\WinMerge\WinMergeU.exe" & Chr(34) & " " & ArgsWinMerge & " " & LeftStringWinmerge & " " & RightStringWinmerge
                        ErrReturnCode = ApplicationWinMerge.Run(StringCommand, 1, True)
                        Set ApplicationWinMerge = Nothing
                    Case "Objets SQL"  '-> to complete
                End Select
            Else
                MsgBox "La catégorie doit être CLIDIFF pour effectuer une comparaison", vbInformation, "Information"
            End If
        End If
    End If
' WinMerge isn't here
Else
    MsgBox "Le programme WinMerge n'est pas installé sur votre poste, veuillez ouvrir un ticket auprès du support DSI", vbCritical + 512, "Attention"
End If
' Final message
If ErrRetCode <> 0 Then
    MsgBox "Une erreur " & ErrReturnCode & " s'est produite, recommencez l'opération...", vbCritical + vbExclamation, "Alerte !"
End If

End Sub

1 Attachments

Discussion

  • Takashi Sawanaka

    Will the following fixes help?

    ArgsWinMerge = " /u /s /dl " & Chr(34) & "Reference" & " /dr " & Chr(34) & "Client" & Chr(34)
    
    ArgsWinMerge = " /u /s /dl " & Chr(34) & "Reference" & Chr(34) & " /dr " & Chr(34) & "Client" & Chr(34)
    
     
  • Patrick SOMMERIA

    Hello,

    Thanks for your answer but it will not, cause I made a copy mistake in my post and the value of this variable is the same as your proposal. I've run the code to verify one more time but it's unsucessfull.
    Should I understand that the WinMerge syntax is correct for you in my code ?

     
  • Patrick SOMMERIA

    moreover, if it is useful, I do not have a plugin in my French version unicode of winmerge. Should I have some ?

     
  • Patrick SOMMERIA

    what is surprising is that when i select the files manually in WinMerge, it works correctly. The paths and files in the "Select files or folders" window visually correspond to the value of my variable "StringCommand" !

     
  • Patrick SOMMERIA

    to complete my previous post, when I play this (=StringCommand value) with the command prompt, it doesn't work either :
    "C:\Program Files (x86)\WinMerge\WinMergeU.exe" /u /s /dl "Reference" /dr "Client" "C:\Dossiers\Migrations eTpta\92001702 (Mon client test 92001072)\PERS20200401185958\ref\com\acx.bat" "C:\Dossiers\Migrations eTpta\92001702 (Mon client test 92001072)\PERS20200401185958\solution\com\acx.bat"

     
  • Patrick SOMMERIA

    sorry, I'd got a mismatch in my code for paths. So, if I play this with the command prompt, it works :

    C:\Users\patrick.sommeria>"C:\Program Files (x86)\WinMerge\WinMergeU.exe" /u /s /dl "Reference" /dr "Client" "C:\Dossiers\Migrations eTpta\Cli\92001072 (Mon client test 92001072)\PERS20200401185958\ref\com\acx.bat" "C:\Dossiers\Migrations eTpta\Cli\92001072 (Mon client test 92001072)\PERS20200401185958\solution\com\acx.bat"

    Maybe my code send invisible bad caracters ?

     
  • Takashi Sawanaka

    Could you perform the following steps on WinMerge?

    1. Copy the exact path to the left of the "Select File or Folder" dialog to the clipboard when the comparison fails.

    2. Close the "Select Files or Folders" dialog.

    3. Press the Ctrl+N key.

    4. Press Ctrl+V on the Left pane

    5. Paste the following into the right pane

    C:\Dossiers\Migrations eTpta\Cli\92001072 (Mon client test 92001072)\PERS20200401185958\ref\com\acx.bat

    1. Press F5 key

    If there is a difference, I think there is a hidden character.

     
  • Patrick SOMMERIA

    There si no difference with your test but ... it's been here from the begining !!!
    I saw no errors on the string value but I have 92001702 (value entered in my EXCEL workbook) instead of 92001072. It was impossible to find the correct path ... Our brain is amazing at correcting what we see ! Unfortunately, the error is ofen between the chair and the keyboard !
    Thank you so much for your patience !

    Now for the next step, I want to provide a report file with the differences. I've looked for topics and WinMerge manuel and I found a syntax. I've tried the following but it doesn't work, what's wrong ?

    "C:\Program Files (x86)\WinMerge\WinMergeU.exe" /u /s /dl "Reference" /dr "Client" "C:\Dossiers\Migrations eTpta\Cli\92001072 (Mon client test 92001072)\PERS20200401185958\ref\com\acx.bat" "C:\Dossiers\Migrations eTpta\Cli\92001072 (Mon client test 92001072)\PERS20200401185958\solution\com\acx.bat" /noprefs /nonintercativ /o "C:\Dossiers\Migrations eTpta\Cli\92001072 (Mon client test 92001072)\PERS20200401185958\report\myreport.html"

    I precise taht the path of report exists

     
  • Takashi Sawanaka

    1. The ability to create HTML reports from the command line is supported since version 2.16.0. You have installed 2.14.0, so please install 2.16.x.
    2. specify "/noninteractive /or" instead of "/nonintercativ /o".
     

    Last edit: Takashi Sawanaka 2020-04-30
  • Patrick SOMMERIA

    Sorry, the correct following is :
    "C:\Program Files (x86)\WinMerge\WinMergeU.exe" /u /s /dl "Reference" /dr "Client" "C:\Dossiers\Migrations eTpta\Cli\92001072 (Mon client test 92001072)\PERS20200401185958\ref\com\acx.bat" "C:\Dossiers\Migrations eTpta\Cli\92001072 (Mon client test 92001072)\PERS20200401185958\solution\com\acx.bat" /noprefs /noninteractive /o "C:\Dossiers\Migrations eTpta\Cli\92001072 (Mon client test 92001072)\PERS20200401185958\report\myreport.html"

    I precise that there is some differences. WinMerge is opening and closing wihout producing report ...

     
  • Takashi Sawanaka

    1. Please specify "/or" instead of "/o".
    2. The ability to create HTML reports from the command line is supported since version 2.16.0. You have installed 2.14.0, so please install 2.16.x.
     

    Last edit: Takashi Sawanaka 2020-04-30
  • Patrick SOMMERIA

    I can't upgrade my version on my own ...
    The curious thing is that I can generate a report manually in WinMerge. You mean that version 2.14 does not allow you to do it from the command line?
    Can we produce a text report?

     
  • Takashi Sawanaka

    You mean that version 2.14 does not allow you to do it from the command line?

    version 2.14 does not allow to create any report from command line.

     

    Last edit: Takashi Sawanaka 2020-04-30
  • Patrick SOMMERIA

    OK, I understand. I'm going to request an upgrade from my enterprise.
    Thank you very much for your advice and your time. It was nice having had an exchange with you.
    Bye

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.