I am very sorry to bother you.
I am using ImageMagick from within VBA (Excel) for some weeks now. It is a great thing the developers did!
Everything works fine. Except the compare method doesn't work as expected or wished (for that matter).
Here is a short code snippet:
Code: Select all
' Declaration
Dim objIM As Object
Dim strFileC As String
dim strFileR As String
Dim varRetVal As Variant
' Create object(s)
Set objIM = CreateObject("ImageMagickObject.MagickImage.1")
' Path to reference file
strFileR = objWs4.Cells(lngRow, 1).Value
' Path to file to compare
strFileC = objWs4.Cells(lngRow, 2).Value
varRetVal = objIM.Compare("-metric", "AE", strFileR, strFileC, "NULL:")
a)
no difference file would be created (because of parameter "NULL:")
b)
a result value is shown (e.g. 4711)
Yes! I did searched the net for a solution and learned that the result value mentioned above is sent to STDERROR and not to STDOUT...
And: yes! I understood that STDERROR can be accessed
a)
from command line
by redirecting it e.g to a file: 2>D:\TestIM\diff.txt (where parameter '2' represents STDERROR) ... or
b)
from within VBA
using a shell object:
Code: Select all
Function execShellCmd(ByVal strCmd As String) As String
' Declaration
Dim objExec
Dim objShell
Dim objStdErr
Dim strLineErr As String
Dim strTextErr As String
' Create object(s)
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec(strCmd)
Set objStdErr = objExec.StdErr
Do
' Read from shell
strLineErr = objStdErr.ReadLine()
' Build single string
If strLineErr <> "" Then
strTextErr = strTextErr & strLineErr
End If
' Exit loop
If objStdErr.AtEndOfStream Then
Exit Do
End If
Loop
' Return resutl to caller
execShellCmd = arrRet
End Function
So after trial and error, reading and reading, trial and error, scratching my head... I surrender and post this question:
Is there a way to access the return value of the compare method from within VBA?
Please: help.