使用VBA批量插入幻灯片
时间:2011-07-01
来源:互联网
① 以InsertFromFile来进行插入,无法保持源格式:
复制内容到剪贴板
Dim FileName As String
Dim K As Integer
For i = 1 To 60
FileName = "****(" & i & ").ppt" ‘注:****为文件名,包括其路径
K = Application.ActivePresentation.Slides.Count
Application.ActivePresentation.Slides.InsertFromFile FileName, K
Next i
End Sub
[ 本帖最后由 dul 于 2011-7-1 14:54 编辑 ] 代码:
Sub InsertSlides()Dim FileName As String
Dim K As Integer
For i = 1 To 60
FileName = "****(" & i & ").ppt" ‘注:****为文件名,包括其路径
K = Application.ActivePresentation.Slides.Count
Application.ActivePresentation.Slides.InsertFromFile FileName, K
Next i
End Sub
作者: dul 发布时间: 2011-07-01
复制内容到剪贴板
Dim oSource As Presentation
Dim oTarget As Presentation
Dim oSlide As Slide
Dim dlgOpen As FileDialog
Dim bMasterShapes As Boolean
Dim i As Integer
Dim FileName As String
Set oTarget = ActivePresentation
For i = 1 To 60
FileName = "※※ (" & i & ").ppt" ’注 ※※为文件名称,包括路径
Set oSource = Presentations.Open(FileName, , , False)
For Each oSlide In oSource.Slides
oSlide.Copy
With oTarget.Slides.Paste
.Design = oSlide.Design
.ColorScheme = oSlide.ColorScheme
If oSlide.FollowMasterBackground = False Then
.FollowMasterBackground = False
With .Background.Fill
.Visible = oSlide.Background.Fill.Visible
.ForeColor = oSlide.Background.Fill.ForeColor
.BackColor = oSlide.Background.Fill.BackColor
End With
Select Case oSlide.Background.Fill.Type
Case Is = msoFillTextured
Select Case oSlide.Background.Fill.TextureType
Case Is = msoTexturePreset
.Background.Fill.PresetTextured _
(oSlide.Background.Fill.PresetTexture)
Case Is = msoTextureUserDefined
End Select
Case Is = msoFillSolid
.Background.Fill.Transparency = 0#
.Background.Fill.Solid
Case Is = msoFillPicture
With oSlide
If .Shapes.Count > 0 Then .Shapes.Range.Visible = False
bMasterShapes = .DisplayMasterShapes
.DisplayMasterShapes = False
.Export oSource.Path & .SlideID & ".png", "PNG"
End With
.Background.Fill.UserPicture _
oSource.Path & oSlide.SlideID & ".png"
Kill (oSource.Path & oSlide.SlideID & ".png")
With oSlide
.DisplayMasterShapes = bMasterShapes
If .Shapes.Count > 0 Then .Shapes.Range.Visible = True
End With
Case Is = msoFillPatterned
.Background.Fill.Patterned _
(oSlide.Background.Fill.Pattern)
Case Is = msoFillGradient
Select Case oSlide.Background.Fill.GradientColorType
Case Is = msoGradientTwoColors
.Background.Fill.TwoColorGradient _
oSlide.Background.Fill.GradientStyle, _
oSlide.Background.Fill.GradientVariant
Case Is = msoGradientPresetColors
.Background.Fill.PresetGradient _
oSlide.Background.Fill.GradientStyle, _
oSlide.Background.Fill.GradientVariant, _
oSlide.Background.Fill.PresetGradientType
Case Is = msoGradientOneColor
.Background.Fill.OneColorGradient _
oSlide.Background.Fill.GradientStyle, _
oSlide.Background.Fill.GradientVariant, _
oSlide.Background.Fill.GradientDegree
End Select
Case Is = msoFillBackground
End Select
End If
End With
Next oSlide
oSource.Close
Set oSource = Nothing
Next i
End Sub
代码:
Sub CopyWithSourceFormating()Dim oSource As Presentation
Dim oTarget As Presentation
Dim oSlide As Slide
Dim dlgOpen As FileDialog
Dim bMasterShapes As Boolean
Dim i As Integer
Dim FileName As String
Set oTarget = ActivePresentation
For i = 1 To 60
FileName = "※※ (" & i & ").ppt" ’注 ※※为文件名称,包括路径
Set oSource = Presentations.Open(FileName, , , False)
For Each oSlide In oSource.Slides
oSlide.Copy
With oTarget.Slides.Paste
.Design = oSlide.Design
.ColorScheme = oSlide.ColorScheme
If oSlide.FollowMasterBackground = False Then
.FollowMasterBackground = False
With .Background.Fill
.Visible = oSlide.Background.Fill.Visible
.ForeColor = oSlide.Background.Fill.ForeColor
.BackColor = oSlide.Background.Fill.BackColor
End With
Select Case oSlide.Background.Fill.Type
Case Is = msoFillTextured
Select Case oSlide.Background.Fill.TextureType
Case Is = msoTexturePreset
.Background.Fill.PresetTextured _
(oSlide.Background.Fill.PresetTexture)
Case Is = msoTextureUserDefined
End Select
Case Is = msoFillSolid
.Background.Fill.Transparency = 0#
.Background.Fill.Solid
Case Is = msoFillPicture
With oSlide
If .Shapes.Count > 0 Then .Shapes.Range.Visible = False
bMasterShapes = .DisplayMasterShapes
.DisplayMasterShapes = False
.Export oSource.Path & .SlideID & ".png", "PNG"
End With
.Background.Fill.UserPicture _
oSource.Path & oSlide.SlideID & ".png"
Kill (oSource.Path & oSlide.SlideID & ".png")
With oSlide
.DisplayMasterShapes = bMasterShapes
If .Shapes.Count > 0 Then .Shapes.Range.Visible = True
End With
Case Is = msoFillPatterned
.Background.Fill.Patterned _
(oSlide.Background.Fill.Pattern)
Case Is = msoFillGradient
Select Case oSlide.Background.Fill.GradientColorType
Case Is = msoGradientTwoColors
.Background.Fill.TwoColorGradient _
oSlide.Background.Fill.GradientStyle, _
oSlide.Background.Fill.GradientVariant
Case Is = msoGradientPresetColors
.Background.Fill.PresetGradient _
oSlide.Background.Fill.GradientStyle, _
oSlide.Background.Fill.GradientVariant, _
oSlide.Background.Fill.PresetGradientType
Case Is = msoGradientOneColor
.Background.Fill.OneColorGradient _
oSlide.Background.Fill.GradientStyle, _
oSlide.Background.Fill.GradientVariant, _
oSlide.Background.Fill.GradientDegree
End Select
Case Is = msoFillBackground
End Select
End If
End With
Next oSlide
oSource.Close
Set oSource = Nothing
Next i
End Sub
作者: dul 发布时间: 2011-07-01
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28