Reputation: 601
can I please get some help with writing a VBA macro in PPT that will perform the following two tasks:
Thanks a lot.
Upvotes: 0
Views: 984
Reputation: 2979
See below for a stripped down VBA example for processing an image file via ImageMagick V6 (V7 changes the convert command to magick). This is a very simple command example. There are hundreds of parameters for ImageMagick and you'll need to find the ones you need for your image processing operation from ImageMagick
' ***********************************************************************************
' Purpose : Convert an image file from one format to another using ImageMagick
' Dependencies : Requires ImageMagic DLL package for Windows (V6) to be pre-installed
' Author : Jamie Garroch of YOUpresent Ltd. (http://youpresent.co.uk/)
' ***********************************************************************************
Public Sub TestImageMagic()
Dim sCmd As String
Dim retval As Variant
Const ImgIn = "C:\Temp\ImageIn.svg"
Const ImgOut = "C:\Temp\ImageOut.png"
Const QUOT = """"
' Construct the ImageMagick command line in the format:
' "C:\Program Files\ImageMagick-6.9.1-Q16\convert" "C:\Temp\ImageIn.svg" "C:\Temp\ImageOut.png"
sCmd = QUOT & GetInstallPathIM & "\" & "convert" & QUOT & _
" " & QUOT & ImgIn & QUOT & _
" " & QUOT & ImgOut & QUOT
On Error Resume Next
' Process the image with ImageMagic
If Len(sCmd) <= 8192 Then retval = oShell.Run(sCmd, 0, True)
If retval <> 0 Or Err <> 0 Then
' Manage errors
End If
On Error Goto 0
End Sub
' ***********************************************************************************
' Purpose : Function to return the installation path for ImageMagic
' from the Windows Environment Path string.
' Author : Jamie Garroch of YOUpresent Ltd. (http://youpresent.co.uk/)
' ***********************************************************************************
Private Function GetImageMagickPath() As String
Dim WinPath As String ' Windows Environment Path string
Dim IM As Integer ' Position of the start of ImageMagic string
Dim PathStart As Integer ' Position of first left semi-colon of the ImageMagic string
Dim PathEnd As Integer ' Position of right semi-colon of the ImageMagic string
' Get the Windows Environment Path string
WinPath = Environ("PATH")
' Parse out the ImageMagick path by looking for ImageMagick and then searching back and forwards to the previous and next occurrence of ";"
IM = InStr(1, WinPath, "ImageMagick")
If IM > 0 Then
PathStart = InStrRev(WinPath, ";", IM) + 1
PathEnd = InStr(IM, WinPath, ";")
GetImageMagickPath = Mid(WinPath, PathStart, PathEnd - PathStart)
Else
MsgBox "ImageMagick components aren't installed!"
End If
End Function
Upvotes: 1