20170814xlVBA PowerPoint分类插图加说明
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分类插图加说明的更多相关文章
- LaTeX技巧012:LaTeX 插图加载宏包
LaTeX 插图加载宏包.支持 LaTeX - DVIPDFMx; pdfLaTeX; XeLaTeX 三种编译方式,支持 eps/pdf/jpg/png 等图片格式. % Put this snip ...
- [功能改进]Live Writer发博支持“建分类、加标签、写摘要”
以前您在园子里用Windows Live Wirter发布博文是不是有以下三个不爽: 不爽1:如果想在发布随笔时新建分类并将随笔添加至该分类,需要先在博客后台添加分类,然后在Live Writer中刷 ...
- magento -- 给后台分类管理页的分类商品加一栏商品类型
当使用特定分类来控制前台的商品显示时,后台分类管理页的分类商品只有编号.名称.SKU和价格这几栏,选择特定商品相当不便. 可以在这里多加一栏商品类型用来筛选商品,添加的方式很简单. 打开文件/app/ ...
- PowerPoint无法正常加载MathType的解决方法
MathType是一款十分便捷的数学公式编辑器,可以和很多办公软件和网站兼容使用,我们日常用的比较多的也就是Office和WPS,更具体的说是Word\Excel\PPT等等一系列办公常用软件. 不过 ...
- effective OC2.0 52阅读笔记(四 协议与分类)
23 通过委托与数据源协议进行对象间通信 总结:委托模式的常规委托模式中,信息从类Class流向受委托者delegate.数据源模式,信息从数据源datasource流向class.数据源和受委托者可 ...
- 常用分类列表wp_list_categories()
使用: <ul> <?php $args= array( 'depth'=>1, 'orderby'=>id, 'style'=>none ); wp_list_c ...
- Office启动加载vs。。。项
PowerPoint: 选项->加载项->Chinese Translation Addin->管理[COM加载项]转到->取消Chinese Translation Addi ...
- 监督学习——logistic进行二分类(python)
线性回归及sgd/bgd的介绍: 监督学习--随机梯度下降算法(sgd)和批梯度下降算法(bgd) 训练数据形式: (第一列代表x1,第二列代表 x2,第三列代表 数据标签 用 0/ ...
- (转!)利用Keras实现图像分类与颜色分类
2018-07-19 全部谷歌渣翻加略微修改 大家将就的看哈 建议大佬们还是看看原文 点击收获原文 其中用到的示例文件 multi-output-classification 大家可以点击 下载 . ...
随机推荐
- 持续集成之二:搭建SVN服务器(subversion)
安装环境 Red Hat Enterprise Linux Server release 7.3 (Maipo) jdk1.7.0_80 subversion-1.10.3.tar.gz apr-1. ...
- JMeter4.0二次开发之导入eclipse
1.先建立工程,命名为JMeter4.0. JDK版本为10.0.1 2.在官网下载src文件,通过文件系统导入到JMeter4.0工程中 3.在ant中选择download_jars,ant会自动下 ...
- appium记录
npm uninstall appium -g npm install -g cnpm --registry=https://registry.npm.taobao.org cnpm install ...
- RocketMQ事务消费和顺序消费详解
一.RocketMq有3中消息类型 1.普通消费 2. 顺序消费 3.事务消费 顺序消费场景 在网购的时候,我们需要下单,那么下单需要假如有三个顺序,第一.创建订单 ,第二:订单付款,第三:订单完成. ...
- MySQL性能分析和优化
1. EXPLAIN 优化你的 SELECT 查询 2. 当只要一行数据时使用 LIMIT 1 3. 为搜索字段建索引 like %最好放右边 4. 尽可能的使用 NOT NULL 5. 在Join表 ...
- java.lang.NoClassDefFoundError: org/apache/http/client/config/RequestConfig
java 错误.java.lang.NoClassDefFoundError: org/apache/http/client/config/RequestConfig 本质上是httpClient的j ...
- Web安全学习笔记之DES算法实例详解
转自http://www.hankcs.com/security/des-algorithm-illustrated.html 译自J. Orlin Grabbe的名作<DES Algorith ...
- Jsp中如何通过Jsp调用Java类中的方法
Jsp中如何通过Jsp调用Java类中的方法 1.新建一个项目,在src文件夹下添加一个包:如:cn.tianaoweb.com; 2.再在包中添加一个类:如 package com; public ...
- log4j 根据类名指定文件
log4j.logger.io.netty=INFO, stdout, spiderlog4j.logger.com.ld.net.spider=INFO, stdout, spider log4j. ...
- 20145127《java程序设计》第三次实验
实验三 敏捷开发与XP实践 一.实验内容及其步骤 1.配置开源中国公钥 2.找到ssh公钥 3.在开源中国添加公钥 4.下载同组同学项目 5.推送代码到开源中国 6.推送代码成功 二.实验感想总结: ...