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. 《算法C语言实现》————三道题目

    1.对于N = 10,100和1000,记录你的运行环境中分别运行一下程序所花费的时间.(用python) import datetime global a a = 0 def time_1(s): ...

  2. eclipse调优

    基于Eclipse 4.7.0 (Oxygen) 目的:加快eclipse启动速度 修改eclipse安装目录下配置文件eclipse.ini(1)指定eclipse运行的jre,不让其进行搜索-vm ...

  3. Java实现递归将嵌套Map里的字段名由驼峰转为下划线

    摘要: 使用Java语言递归地将Map里的字段名由驼峰转下划线.通过此例可以学习如何递归地解析任意嵌套的List-Map容器结构. 难度:初级 概述 在进行多语言混合编程时,由于编程规范的不同, 有时 ...

  4. python练习题-写一个函数,打印所有包含copy方法的内置对象

    代码: #encoding=utf-8for i in dir(__builtins__):    #print "i:",i    try: #这里的i是个字符串,并不能直接用d ...

  5. 谷歌笔试题--给定一个集合A=[0,1,3,8](该集合中的元素都是在0,9之间的数字,但未必全部包含), 指定任意一个正整数K,请用A中的元素组成一个大于K的最小正整数。

    谷歌笔试题--给定一个集合A=[0,1,3,8](该集合中的元素都是在0,9之间的数字,但未必全部包含), 指定任意一个正整数K,请用A中的元素组成一个大于K的最小正整数. Google2009华南地 ...

  6. 解析分布式锁之Redis实现(二)

    摘要:在前文中提及了实现分布式锁目前有三种流行方案,分别为基于数据库.Redis.Zookeeper的方案,本文主要阐述基于Redis的分布式锁,分布式架构设计如今在企业中被大量的应用,而在不同的分布 ...

  7. pollard_rho 学习总结 Miller_Rabbin 复习总结

    吐槽一下名字,泼辣的肉..OwO 我们知道分解出一个整数的所有质因子是O(sqrt(n)/ln(n))的 但是当n=10^18的时候就显得非常无力的 这个算法可以在大概O(n^(1/4))的时间复杂度 ...

  8. Python3 itchat实现微信定时发送群消息

    Python3 itchat实现微信定时发送群消息 一.简介 1,使用微信,定时往指定的微信群里发送指定信息. 2,需要发送的内容使用excel进行维护,指定要发送的微信群名.时间.内容. 二.py库 ...

  9. ”MySQL查询优化“学习总结

    查询优化有几种方法,下面分别介绍. 切分查询 一条大的语句(涉及很多行)一次会锁住很多数据(不利于高并发). 占满整个事务日志,耗尽系统资源.阻塞很多小的但很重要的查询. 分解关联查询 关联查询分解方 ...

  10. 04: python常用模块

    目录: 1.1 时间模块time() 与 datetime() 1.2 random()模块 1.3 os模块 1.4 sys模块 1.5 tarfile用于将文件夹归档成 .tar的文件 1.6 s ...