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. cmd中mysql中文乱码问题

    以下为自己亲试: 解决cmd中MySQL查询和命令返回的中文乱码问题 1.修改cmd字符集方法 rem 切换到UTF-8 chcp 65001 rem 切换到默认的GBK chcp 936 rem 美 ...

  2. web前端----jQuery扩展(很重要!!)

    1.jQuery扩展语法 把扩展的内容就可以写到xxxx.js文件了,在主文件中直接导入就行了. 用法1.$.xxx() $.extend({ "GDP": function () ...

  3. Cannot find JRE '1.8'

  4. python的时间处理-time模块

    time模块 时间的表示方法有三种: 时间戳:表示的是从1970年1月1日0点至今的秒数 格式化字符串表示:这种表示更习惯我们通常的读法,如2018-04-24 00:00:00 格式化元祖表示:是一 ...

  5. Sybase 存储过程中IF的用法

    Sybase 存储过程中IF的用法 --@i_val 为参数 or @i_val is null then begin --执行内容 end; end if;

  6. 20145221《网络对抗》PC平台逆向破解

    20145221<网络对抗>PC平台逆向破解 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户 ...

  7. Win32程序支持命令行参数的做法(转载)

    转载:http://www.cnblogs.com/lanzhi/p/6470406.html 转载:http://blog.csdn.net/kelsel/article/details/52759 ...

  8. C# MD5一句话加密

    System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5")

  9. ubuntu16.04下无线网卡无法正常连网

    背景:无线网卡初次连接可以正常上网,但是用了一会儿就会出现无法上网的情况 版本: Ubuntu 16.04 一.分析: 1.使用ifconfig命令发现不会显示无线网卡,说明无线网卡被关闭,笔者输出的 ...

  10. kubernetes 命令记录

    操作基本命令:   通过yaml文件创建: kubectl create -f xxx.yaml (不建议使用,无法更新,必须先delete) kubectl apply -f xxx.yaml (创 ...