0

can I please get some help with writing a VBA macro in PPT that will perform the following two tasks:

  1. Insert a new slide (Title and Content format)
  2. Insert an image (in SVG format) from a URL into content area. The URL has a number of query string parameters that renders a "svg" image.

Thanks a lot.

5
  • 1
    PowerPoint doesn't accept SVG graphics, so the rest of the question is moot. Commented Jun 2, 2016 at 15:44
  • Thanks @steve-rindsberg. Do you know if it's possible to convert SVG graphics to PNG using VBA and then insert the PNG graphic? Commented Jun 2, 2016 at 16:39
  • 1
    You can't directly convert SVG in VBA (unless you want to write a transcoder from scratch!) but you could Shell a conversation command from VBA to an external converter such as ImageMagick (which I've done before). Commented Jun 2, 2016 at 17:19
  • Thanks @jamieg. Would you mind sharing your VBA script? Also, does this mean that if I were to share the Macro enabled PPT files with others, they would need to have ImageMagick installed on their machines for this to work? Commented Jun 2, 2016 at 19:50
  • 1
    @Raj Yes, in order for a script that calls on ImageMagick to work, it'd have to have a copy of Image Magick to work on. But have a look here: imagemagick.org/script/ImageMagickObject.php Commented Jun 3, 2016 at 18:23

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.