• PPT自动载入图片并矩阵分布


    最近有学生问到,能不能快速的向PPT一个页面里插入成百张图片,并让它们按统一大小的矩形排布到页面上。我写了以下代码可以在第1页中按照指定横向和纵向矩形数目,填充指定路径下的图片。

     1 Sub LoadPicToShape()
     2     Dim mPageWidth As Double, mPageHeight As Double
     3     Dim X_Count As Integer, Y_Count As Integer
     4     Dim mShapeWidth As Double, mShapeHeight As Double
     5     Dim mShape As Shape
     6     Dim mPicPath As String, mPicName As String
     7 
     8     '清除所有第1页上的所有形状
     9 
    10     Do Until ActivePresentation.Slides(1).Shapes.Count = 0
    11         ActivePresentation.Slides(1).Shapes(1).Delete
    12     Loop
    13 
    14     mPageWidth = ActivePresentation.PageSetup.SlideWidth '获取页面宽度
    15     mPageHeight = ActivePresentation.PageSetup.SlideHeight '获取页面高度
    16 
    17     '这2个参数可以自己调整
    18     X_Count = 10: Y_Count = 6 'X方向图片数量,Y方向图片数量
    19     mShapeWidth = mPageWidth / X_Count: mShapeHeight = mPageHeight / Y_Count '图片形状的宽度和高度
    20 
    21     '指定图片所在文件夹路径,并开始获取第1张jpg图片名称
    22     mPicPath = "E:Office培训素材图片"
    23     mPicName = Dir(mPicPath & "*.jpg")
    24     If mPicName = "" Then Exit Sub
    25 
    26     '以下首先生成矩形形状,然后填充图片到形状
    27     For j = 1 To Y_Count
    28         For i = 1 To X_Count
    29             Set mShape = ActivePresentation.Slides(1).Shapes.AddShape(msoShapeRectangle, _
    30                 (i - 1) * mShapeWidth, (j - 1) * mShapeHeight, mShapeWidth, mShapeHeight)
    31             mShape.Fill.UserPicture mPicPath & "" & mPicName
    32             mPicName = Dir
    33             If mPicName = "" Then mPicName = Dir(mPicPath & "*.jpg") '图片总数不够数,从头开始重复加载
    34         Next
    35     Next
    36 End Sub
  • 相关阅读:
    Maven工程读取properties文件过程
    Nginx实现高可用(了解)
    使用Nginx实现负载均衡(tomcat集群之后实现交叉访问)
    使用Nginx实现反向代理过程(一台服务器部署两个网站)
    一台服务器,通过不同域名区分不同主机,配置步骤
    EditPlus5.0破解激活
    [通知] 博客停更
    [论文理解] 活体检测算法论文小结 (一)
    [CUDA] CUDA编程入门
    [学习笔记]《机器学习基础》 课程总结(一)
  • 原文地址:https://www.cnblogs.com/alexywt/p/4731149.html
Copyright © 2020-2023  润新知