Public Sub AddPictures()
Dim ppApp As PowerPoint.Application
Set ppApp = New PowerPoint.Application
Dim Pre As PowerPoint.Presentation
Dim NewSld As PowerPoint.Slide
Dim tShp As PowerPoint.Shape
Dim pShp As PowerPoint.Shape Const PPT_NAME As String = "图片.ppt"
Dim pptPath As String pptPath = ThisWorkbook.Path & "\" & PPT_NAME
Set Pre = ppApp.Presentations.Add(msoTrue)
Pre.SaveAs pptPath Dim PicIndex As Long
Dim SldIndex As Long
SldIndex = 0
With ThisWorkbook.Sheets("数据")
'预先排序
CustomSort .UsedRange
'逐个类别 逐个单位
endrow = .Cells(.Cells.Rows.Count, 2).End(xlUp).Row
For i = 2 To endrow
If .Cells(i, "G").Text <> .Cells(i - 1, "G").Text Then
'若类别不同
SldIndex = SldIndex + 1
PicIndex = 1
Debug.Print i; "插入新幻灯片"; SldIndex
Set NewSld = Pre.Slides.Add(Pre.Slides.Count + 1, ppLayoutBlank)
NewSld.Name = SldIndex
Debug.Print i; "插入图片"; PicIndex
Set pShp = InsertPicture(Pre, NewSld, .Cells(i, 12).Text, PicIndex)
Text = .Cells(i, 2).Text & " " & .Cells(i, 3).Text & " " & .Cells(i, 4).Text & " " & .Cells(i, 5).Text & Chr(13) & .Cells(i, 6).Text
Set tShp = InsertTextBox(NewSld, pShp, Text)
Else
'若类别相同
If .Cells(i, "D").Text <> .Cells(i - 1, "D").Text Then
'若单位不同
PicIndex = 1
SldIndex = SldIndex + 1
Debug.Print i; "插入新幻灯片"; SldIndex
Set NewSld = Pre.Slides.Add(Pre.Slides.Count + 1, ppLayoutBlank)
NewSld.Name = SldIndex
Debug.Print i; "插入图片1"
Set pShp = InsertPicture(Pre, NewSld, .Cells(i, 12).Text, PicIndex)
Text = .Cells(i, 2).Text & " " & .Cells(i, 3).Text & " " & .Cells(i, 4).Text & " " & .Cells(i, 5).Text & Chr(13) & .Cells(i, 6).Text
Set tShp = InsertTextBox(NewSld, pShp, Text)
Else
'若单位相同
PicIndex = PicIndex + 1
PicIndex = (PicIndex - 1) Mod 4 + 1
If PicIndex = 1 Then '当同类超过一页幻灯片时
SldIndex = SldIndex + 1
Debug.Print i; ">5插入新幻灯片"; SldIndex
Set NewSld = Pre.Slides.Add(Pre.Slides.Count + 1, ppLayoutBlank)
NewSld.Name = SldIndex
Debug.Print i; ">5同类同单位插入图片"; PicIndex
Set pShp = InsertPicture(Pre, NewSld, .Cells(i, 12).Text, PicIndex)
Text = .Cells(i, 2).Text & " " & .Cells(i, 3).Text & " " & .Cells(i, 4).Text & " " & .Cells(i, 5).Text & Chr(13) & .Cells(i, 6).Text
Set tShp = InsertTextBox(NewSld, pShp, Text)
Else
Debug.Print i; "同类同单位插入图片"; PicIndex
Set pShp = InsertPicture(Pre, NewSld, .Cells(i, 12).Text, PicIndex)
Text = .Cells(i, 2).Text & " " & .Cells(i, 3).Text & " " & .Cells(i, 4).Text & " " & .Cells(i, 5).Text & Chr(13) & .Cells(i, 6).Text
Set tShp = InsertTextBox(NewSld, pShp, Text)
End If
End If
End If
Next i
End With
Pre.Save
Pre.Close
ppApp.Quit
Set ppApp = Nothing End Sub
Private Sub CustomSort(ByVal RngWithTitle As Range)
With RngWithTitle
.Sort _
Key1:=RngWithTitle.Cells(1, 7), Order1:=xlAscending, _
Key2:=RngWithTitle.Cells(1, 4), Order2:=xlAscending, _
Header:=xlYes, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod:=xlPinYin
End With
End Sub Private Function InsertPicture(ByVal Pre As PowerPoint.Presentation, ByVal NewSld As PowerPoint.Slide, _
ByVal ImagePath As String, ByVal Pos As Long) As PowerPoint.Shape
Dim Shp As PowerPoint.Shape
Set Shp = NewSld.Shapes.AddPicture(ImagePath, msoFalse, msoTrue, CLeft(Pre, Pos), CTop(Pre, Pos), CWidth(Pre, Pos), CHeight(Pre, Pos))
Set InsertPicture = Shp
Set Shp = Nothing
End Function Private Function CLeft(ByVal Pre As PowerPoint.Presentation, ByVal Pos As Long, Optional JG As Long = 10) As Double
Dim SW As Double
Dim SH As Double
SW = Pre.PageSetup.SlideWidth
SH = Pre.PageSetup.SlideHeight
Select Case Pos
Case 1, 3
CLeft = JG
Case 2, 4
CLeft = JG * 3 + SW / 2
End Select
End Function
Private Function CTop(ByVal Pre As PowerPoint.Presentation, ByVal Pos As Long, Optional JG As Long = 10) As Double
Dim SW As Double
Dim SH As Double
SW = Pre.PageSetup.SlideWidth
SH = Pre.PageSetup.SlideHeight
Select Case Pos
Case 1, 2
CTop = JG
Case 3, 4
CTop = JG * 3 + SH / 2
End Select
End Function
Private Function CWidth(ByVal Pre As Presentation, Optional JG As Long = 10) As Double
Dim SW As Double
Dim SH As Double
SW = Pre.PageSetup.SlideWidth
SH = Pre.PageSetup.SlideHeight
CWidth = (SW - 4 * JG) / 2 - 30
End Function
Private Function CHeight(ByVal Pre As Presentation, Optional JG As Long = 10) As Double
Dim SW As Double
Dim SH As Double
SW = Pre.PageSetup.SlideWidth
SH = Pre.PageSetup.SlideHeight
CHeight = (SH - 4 * JG) / 2 - 100
End Function Private Function InsertTextBox(ByVal NewSld As PowerPoint.Slide, ByVal pShp As PowerPoint.Shape, ByVal Text As String) As PowerPoint.Shape Dim Shp As PowerPoint.Shape
Dim Pos As Long
Dim Tr As PowerPoint.TextRange With NewSld
Set Shp = .Shapes.AddTextBox(msoTextOrientationHorizontal, pShp.Left, pShp.Top + pShp.Height, pShp.Width, 50)
With Shp
.TextFrame.WordWrap = msoTrue
With .TextFrame.TextRange
With .ParagraphFormat
.LineRuleWithin = msoTrue
.SpaceWithin = 1
.LineRuleBefore = msoTrue
.SpaceBefore = 0.5
.LineRuleAfter = msoTrue
.SpaceAfter = 0
End With
myText = Text
.Text = myText
Pos = InStr(myText, Chr(13)) Set Tr = .Characters(1, Pos)
With Tr
.Font.Size = 14
.Font.Color.RGB = RGB(Red:=255, Green:=51, Blue:=255)
End With Set Tr = .Characters(Pos + 1, Len(myText) - Pos)
With Tr
.Font.Size = 18
.Font.Color.RGB = RGB(Red:=255, Green:=51, Blue:=0)
End With End With
End With End With
Set InsertTextBox = Shp
Set Shp = Nothing
End Function

  

20170814xlVBA PowerPoint分类插图加说明的更多相关文章

  1. LaTeX技巧012:LaTeX 插图加载宏包

    LaTeX 插图加载宏包.支持 LaTeX - DVIPDFMx; pdfLaTeX; XeLaTeX 三种编译方式,支持 eps/pdf/jpg/png 等图片格式. % Put this snip ...

  2. [功能改进]Live Writer发博支持“建分类、加标签、写摘要”

    以前您在园子里用Windows Live Wirter发布博文是不是有以下三个不爽: 不爽1:如果想在发布随笔时新建分类并将随笔添加至该分类,需要先在博客后台添加分类,然后在Live Writer中刷 ...

  3. magento -- 给后台分类管理页的分类商品加一栏商品类型

    当使用特定分类来控制前台的商品显示时,后台分类管理页的分类商品只有编号.名称.SKU和价格这几栏,选择特定商品相当不便. 可以在这里多加一栏商品类型用来筛选商品,添加的方式很简单. 打开文件/app/ ...

  4. PowerPoint无法正常加载MathType的解决方法

    MathType是一款十分便捷的数学公式编辑器,可以和很多办公软件和网站兼容使用,我们日常用的比较多的也就是Office和WPS,更具体的说是Word\Excel\PPT等等一系列办公常用软件. 不过 ...

  5. effective OC2.0 52阅读笔记(四 协议与分类)

    23 通过委托与数据源协议进行对象间通信 总结:委托模式的常规委托模式中,信息从类Class流向受委托者delegate.数据源模式,信息从数据源datasource流向class.数据源和受委托者可 ...

  6. 常用分类列表wp_list_categories()

    使用: <ul> <?php $args= array( 'depth'=>1, 'orderby'=>id, 'style'=>none ); wp_list_c ...

  7. Office启动加载vs。。。项

    PowerPoint: 选项->加载项->Chinese Translation Addin->管理[COM加载项]转到->取消Chinese Translation Addi ...

  8. 监督学习——logistic进行二分类(python)

    线性回归及sgd/bgd的介绍: 监督学习--随机梯度下降算法(sgd)和批梯度下降算法(bgd) 训练数据形式:          (第一列代表x1,第二列代表 x2,第三列代表 数据标签 用 0/ ...

  9. (转!)利用Keras实现图像分类与颜色分类

    2018-07-19 全部谷歌渣翻加略微修改 大家将就的看哈 建议大佬们还是看看原文 点击收获原文 其中用到的示例文件 multi-output-classification 大家可以点击 下载 . ...

随机推荐

  1. Azkaban学习笔记(二)

    官方文档:http://azkaban.github.io/ 一.Azkaban主要的组成: 1. 关系型数据库——MySQL 2. AzkabanWebServer 3. AzkabanExcuto ...

  2. hive支持sql大全(收藏版)

    hive操作数据库还是比较方便的,因此才会有hbase与hive整合.下面我们hive的强大功能吧.为了增强阅读性,下面提几个问题: 1.hive支持哪些运算符? 2.hive是否支持左右连接? 3. ...

  3. MyEclipse 相关设置

    1. MyElipse复制项目后,修改项目的发布名称的方式.右击你的项目,选择 properties -- > MyElipse -- > web,然后修改名称即可. 2. IDE查看源代 ...

  4. Linux服务器---安装jdk

    安装jdk jdk是运行或者开发java的必须工具,很多软件都会依赖jdk,因此必须学会安装jdk 1.查看当前系统的jdk情况 [root@localhost wj]# rpm -qa | grep ...

  5. 手撕vue-cli配置——webpack.base.conf.js篇

    在开始写webpack.base.conf.js(简称base)之前,我们先来看一下vue-loader.conf.js这个文件,毕竟在base中我们还会用到: 'use strict' //引入前一 ...

  6. 开源|如何使用CNN将视频从2D到3D进行自动转换(附源代码)

    http://www.sohu.com/a/128924237_642762 全球人工智能 文章来源:GitHub 作者:Eric Junyuan Xie 它是如何运行的? 在运行代码之前,请先根据官 ...

  7. c++第十一天

    <c++ primer, 5E> 第68页到第81页,笔记: 1.读取未知量的string对象示例 #include<iostream> using std::cin; usi ...

  8. Kafka学习之(七)搭建kafka可视化服务Kafka Eagle

    一.下载安装包  kafka-eagle-bin-1.2.4.tar.gz 百度云链接:链接:https://pan.baidu.com/s/1SNIkpsvs20A_Ljtx5PaMuA 密码:o4 ...

  9. Android 深入理解Activity 页面Intent跳转

  10. Python3基础 str format 位置参数与关键字参数

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...