ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 588|回复: 5

[求助] excel中A列单元格内容转为PPT每页标题如何解决?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2021-3-10 09:38 | 显示全部楼层 |阅读模式
想excel中A列单元格内容转为PPT每页标题
网上找到下面宏
是选定了当前sheet的A列,然后把这一列内容拷贝到ppt中,
每一个单元格值做ppt的一页中的一个标题

但是
Set ptSld = ptPre.Slides.Add(Index:=ptPre.Slides.Count + 1, Layout:=ppLayoutBlank)
到这句就出错了   后面不知道还有没有错
请各位老师指导修改一下


Sub test()

Dim ptApp As Object
Set ptApp = CreateObject("PowerPoint.Application")
Dim ptPre As Object
Set ptPre = ptApp.Presentations.Add
Dim ptSld As Object
Dim ptShape As Object
ptApp.Visible = msoTrue

ActiveSheet.Names.Add Name:="NewWord", RefersTo:="=OFFSET($A$1,0,0,COUNTA($A:$A))"
Set R = ActiveSheet.Names("NewWord").RefersToRange
dd = R.Count - 1

For rr = 2 To dd + 1
Set ptSld = ptPre.Slides.Add(Index:=ptPre.Slides.Count + 1, Layout:=ppLayoutBlank)
Set ptShape = ptSld.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=10, Top:=17, Width:=700, Height:=50)
With ptShape.TextFrame
.TextRange.Text = R(rr)
.TextRange.Font.Name = "楷体_GB2312"
.TextRange.Font.Size = 30
.TextRange.Font.Color.RGB = RGB(Red:=0, Green:=0, Blue:=255)
.TextRange.Font.Bold = True
End With

Set ptShape = ptSld.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=10, Top:=80, Width:=700, Height:=450)

With ptShape.TextFrame
.TextRange.Text = "This is for test!"
.TextRange.Font.Name = "楷体_GB2312"
.TextRange.Font.Size = 25
End With

ptSld.Shapes(2).TextFrame.TextRange.Characters.Font.Color = vbBlack
Next rr
End Sub



TA的精华主题

TA的得分主题

 楼主| 发表于 2021-3-10 09:41 | 显示全部楼层
excel中A列单元格内容转为PPT每页标题

excel中A列单元格内容转为PPT每页标题.zip

10.57 KB, 下载次数: 14

TA的精华主题

TA的得分主题

发表于 2021-3-11 16:00 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
  1. Sub test()
  2.     Dim ptApp As Object
  3.     Set ptApp = CreateObject("PowerPoint.Application")
  4.     Dim ptPre As Object
  5.     Set ptPre = ptApp.Presentations.Add
  6.     Dim ptSld As Object
  7.     Dim ptShape As Object
  8.     ptApp.Visible = msoTrue
  9.     ActiveSheet.Names.Add Name:="NewWord", RefersTo:="=OFFSET($A$1,0,0,COUNTA($A:$A))"
  10.     Set R = ActiveSheet.Names("NewWord").RefersToRange
  11.     dd = R.Count - 1
  12.     For rr = 1 To dd
  13.         Set ptSld = ptPre.Slides.Add(ptPre.Slides.Count + 1, 12)
  14.         Set ptShape = ptSld.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
  15.         Left:=10, Top:=17, Width:=700, Height:=50)
  16.         With ptShape.TextFrame
  17.             .TextRange.Text = R(rr)
  18.             .TextRange.Font.Name = "楷体_GB2312"
  19.             .TextRange.Font.Size = 30
  20.             .TextRange.Font.Color.RGB = RGB(Red:=0, Green:=0, Blue:=255)
  21.             .TextRange.Font.Bold = True
  22.         End With
  23.         Set ptShape = ptSld.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
  24.         Left:=10, Top:=80, Width:=700, Height:=450)
  25.         With ptShape.TextFrame
  26.             .TextRange.Text = "This is for test!"
  27.             .TextRange.Font.Name = "楷体_GB2312"
  28.             .TextRange.Font.Size = 25
  29.         End With
  30.         ptSld.Shapes(2).TextFrame.TextRange.Characters.Font.Color = vbBlack
  31.     Next rr
  32. End Sub
复制代码


TA的精华主题

TA的得分主题

 楼主| 发表于 2021-3-11 21:23 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

果然厉害   谢谢老师

还有  请教老师
下面文本栏显示This is for test!
能否  和标题栏一样  从B列提取内容 那样就更完美了

TA的精华主题

TA的得分主题

发表于 2021-3-11 22:13 | 显示全部楼层
ym1080 发表于 2021-3-11 21:23
果然厉害   谢谢老师

还有  请教老师

先在B列中添加内容,代码如下:
  1. Sub test()
  2.     Dim ptApp As Object
  3.     Set ptApp = CreateObject("PowerPoint.Application")
  4.     Dim ptPre As Object
  5.     Set ptPre = ptApp.Presentations.Add
  6.     Dim ptSld As Object
  7.     Dim ptShape As Object
  8.     Dim i&, arr
  9.     ptApp.Visible = msoTrue
  10.     With Sheets("Sheet1")
  11.         arr = .Range("A1:B" & .Cells(.Rows.Count, 1).End(xlUp).Row)
  12.     End With
  13.     For i = 1 To UBound(arr)
  14.         Set ptSld = ptPre.Slides.Add(ptPre.Slides.Count + 1, 12)
  15.         Set ptShape = ptSld.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
  16.         Left:=10, Top:=17, Width:=700, Height:=50)
  17.         With ptShape.TextFrame
  18.             .TextRange.Text = arr(i, 1)
  19.             .TextRange.Font.Name = "楷体_GB2312"
  20.             .TextRange.Font.Size = 30
  21.             .TextRange.Font.Color.RGB = RGB(Red:=0, Green:=0, Blue:=255)
  22.             .TextRange.Font.Bold = True
  23.         End With
  24.         Set ptShape = ptSld.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
  25.         Left:=10, Top:=80, Width:=700, Height:=450)
  26.         With ptShape.TextFrame
  27.             .TextRange.Text = arr(i, 2)
  28.             .TextRange.Font.Name = "楷体_GB2312"
  29.             .TextRange.Font.Size = 25
  30.         End With
  31.         ptSld.Shapes(2).TextFrame.TextRange.Characters.Font.Color = vbBlack
  32.     Next
  33. End Sub
复制代码


TA的精华主题

TA的得分主题

 楼主| 发表于 2021-3-12 15:41 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
shenjianrong163 发表于 2021-3-11 22:13
先在B列中添加内容,代码如下:

完美   谢谢指教
祝万事如意!
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-3-29 02:33 , Processed in 0.040541 second(s), 10 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表