Const ModelText As String = "机构名称"
Const ModelName As String = "测试文件.pptx" Sub NextSeven_CodeFrame()
'应用程序设置
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
'错误处理
On Error GoTo ErrHandler
'计时器
Dim StartTime, UsedTime As Variant
StartTime = VBA.Timer '变量声明
Dim Wb As Workbook
Dim Sht As Worksheet
Dim Rng As Range
Dim Arr As Variant
Dim EndRow As Long Dim pApp As Object
Dim Pre As Object
'Dim pApp As PowerPoint.Application
'Dim pre As PowerPoint.Presentation Dim FindStr As String
Dim ReplaceStr As String
Dim FilePath As String
Dim FolderPath As String
Dim tmp As String Dim FileName As String
FileName = Left(ModelName, InStrRev(ModelName, ".") - 1)
'实例化对象
Set Wb = Application.ThisWorkbook
Set Sht = Wb.Worksheets(1)
FolderPath = Wb.Path & "\"
'Set pApp = New PowerPoint.Application
Set pApp = CreateObject("PowerPoint.Application")
Debug.Print FolderPath & ModelName
Set Pre = pApp.Presentations.Open(FolderPath & ModelName)
With Sht
EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
Set Rng = .Range("A1:Z" & EndRow)
Arr = Rng.Value
For i = LBound(Arr) To UBound(Arr)
If i = 1 Then
FindStr = ModelText
ReplaceStr = Arr(i, 1)
FilePath = FolderPath & FileName & "_予" & Arr(i, 1) & ".pdf"
ReplaceAndPublish Pre, FilePath, FindStr, ReplaceStr
Else
FindStr = Arr(i - 1, 1)
ReplaceStr = Arr(i, 1)
FilePath = FolderPath & FileName & "_予" & Arr(i, 1) & ".pdf"
ReplaceAndPublish Pre, FilePath, FindStr, ReplaceStr
End If
Next i
End With
'运行耗时
UsedTime = VBA.Timer - StartTime
'MsgBox "本次运行耗时:" & Format(UsedTime, "0.0000000秒")
ErrorExit: '错误处理结束,开始环境清理
Pre.Close
Set Pre = Nothing
pApp.Quit
Set pApp = Nothing
Set Wb = Nothing
Set Sht = Nothing
Set Rng = Nothing Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
Exit Sub
ErrHandler:
If Err.Number <> 0 Then
MsgBox Err.Description & "!", vbCritical, "错误提示!"
'Debug.Print Err.Description
Err.Clear
Resume ErrorExit
End If
End Sub
Private Sub ReplaceAndPublish(ByVal Pre As Object, ByVal FilePath As String, ByVal FindText As String, ByVal ReplaceText As String)
Dim sld As PowerPoint.Slide
Dim shp As PowerPoint.Shape
Dim Txt As String
For Each sld In Pre.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame = msoTrue Then
If shp.TextFrame.HasText Then
Txt = shp.TextFrame.TextRange.Text
If InStr(1, Txt, FindText) > 0 Then
shp.TextFrame.TextRange.Text = Replace(Txt, FindText, ReplaceText)
Exit For
End If
End If
End If
Next
Next
Pre.SaveAs FilePath, ppSaveAsPDF
End Sub

  

最新文章

  1. Spring配置bean文件的底层实现方式
  2. FreeCodeCamp 前端初级算法(个人向)
  3. Fragment学习笔记
  4. 解决TIME_WAIT过多造成的问题
  5. nodejs 入门
  6. mysql 命令行操作
  7. python3.4 安装ipython notebook
  8. 增量与位置PID
  9. C# WinForm中 让控件全屏显示的实现代码
  10. [转] Android进阶——安卓接入微信,获取OpenID
  11. duilib入门简明教程 -- VS环境配置(2) Alberl
  12. bzoj3131
  13. jQuery EasyUI 1.4.4 Combobox无法检索中文输入的问题
  14. ERP系统开发平台 (C#语言,支持多数据库)
  15. IOS-textField
  16. keil C51 指针总结
  17. java使用SSH连接Linux系统
  18. 微信公众号 chinaxdt 的 解压密码 mima
  19. LeetCode 1013 Partition Array Into Three Parts With Equal Sum 解题报告
  20. JavaScript 设计模式的七大原则(未完成)

热门文章

  1. SSRS创建复合型图表
  2. Python: Pycharm简单介绍
  3. linux常用命令:chown 命令
  4. LINUX环境变量(一)
  5. Oracle提示错误消息ORA-28001: the password has expired
  6. Centos文件切割利器_split命令及cat命令合并文件
  7. C++面向对象高级开发课程(第二周)
  8. 【转】iOS学习之iOS禁止Touch事件
  9. IDEA Java开发常用插件
  10. 第八章 对称加密算法--AES