First, I tried using the ImageMagickObject 1.0 Type Library:
Code: Select all
Private Sub CommandButtonOkay_Click()
Dim sURL As String, sNetFile As String, sLocalFile As String, _
cmd As String, RetVal As Integer, img As Object
Set img = New ImageMagickObject.MagickImage
sURL = UserForm1.TextBoxImgURL
sLocalFile = "C:\temp\" & UserForm1.TextBoxName
DownloadFile sURL, sLocalFile ' Function to download image from a URL and save it to a local directory
RetVal = img.Convert(sLocalFile, sLocalFile & ".jpg") '<-- This line produces the error
UserForm1.Hide
End Sub
The source file ("C:\temp\image") exists, but the file that was to be created ("C\temp\image.jpg") does not. This is very similar to the question posted here, but I have not been able to find a solution to that so far.
Second, I tried just calling ImageMagick using the Shell command:
Code: Select all
Private Sub CommandButtonOkay_Click()
Dim sURL As String, sNetFile As String, sLocalFile As String, _
cmd As String, RetVal As Integer
sURL = UserForm1.TextBoxImgURL
sLocalFile = "C:\temp\" & UserForm1.TextBoxName
DownloadFile sURL, sLocalFile ' Function to download image from a URL and save it to a local directory
RetVal = Shell("convert.exe """ & sLocalFile & """ """ & sLocalFile & ".jpg""")
UserForm1.Hide
End Sub
So the question then seems to be why is the ImageMagick command working beautifully when it is operating in its own command prompt, but not working at all when operating from within VBA?
[1] I don't know if this is useful information or not, but I'm downloading the images from the internet programmatically, so I have no means of knowing what format I'm getting; however, the image I've been using to test this with is a PNG.