VBA宏从PowerPoint

时间:2016-06-02 14:09:49

标签: vba macros powerpoint powerpoint-vba

我可以帮助您在PPT中编写一个VBA宏来执行以下两项任务:

  1. 插入新幻灯片(标题和内容格式)
  2. 将图像(以SVG格式)从URL插入内容区域。该URL有许多查询字符串参数,用于呈现" svg"图像。
  3. 非常感谢。

1 个答案:

答案 0 :(得分:1)

请参阅下文,了解通过ImageMagick V6处理图像文件的精简版VBA示例(V7将转换命令更改为 magick )。这是一个非常简单的命令示例。 ImageMagick有数百个参数,您需要从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