【发布时间】:2016-07-28 16:43:37
【问题描述】:
早上好,
我有一个 excel 文件,从中可以在 powerpoint 中创建幻灯片。为此,我使用了 vba,一切都使用对 PowerPoint 对象的引用。
但是,这个文件应该在不同版本的 Office 的多台机器上使用,所以我不能使用引用。 我在“Set pptLayout = Presentazione.Slides (1) .CustomLayout”行有错误:运行时错误 438
我该如何解决?
有没有一种方法可以添加空白幻灯片 A4 尺寸而不是使用 ppCustomLayout ???
Option Explicit
'Public PPSlide As Slide
'Public Plate As Variant
Public PlatesOnSheet, Sheet As Single
Public TextOfPlate As String
Public Copies, HowMuch, RowNumber, LastRow As Integer
'Public PPPresentation As PowerPoint.Presentation
'Public pptLayout As CustomLayout
Public PlateHeight As Single
Public PPPresentation, PPSlide, Plate, pptLayout, PowerPointApp As Object
Public Sub Plates()
Set PowerPointApp = CreateObject("PowerPoint.Application")
PowerPointApp.Visible = True
Set PPPresentation = PowerPointApp.Presentations.Open("P:\Per Officina\DA E PER MASSIMO G\Plates MT\NUOVA\Plates mt.pptm", msoTrue)
Set pptLayout = PPPresentation.Slides(1).CustomLayout
Sheet = 1
PlatesOnSheet = 0
PlateHeight = 35
LastRow = 27
While Cells(LastRow, 2) <> "totale"
LastRow = LastRow + 1
Wend
LastRow = LastRow - 2
For RowNumber = 2 To LastRow
TextOfPlate = Cells(RowNumber, 1)
If Cells(RowNumber, 2) = "" Then
Copies = 0
Else
Copies = Cells(RowNumber, 2)
End If
If Copies = 0 Then GoTo SaltaTextOfPlate:
For HowMuch = 1 To Copies
If PlatesOnSheet < 5 Then
Call CreatePlate
Else
PlatesOnSheet = 0
PPPresentation.Slides.AddSlide Index:=Sheet + 1, pcustomlayout:=pptLayout
Sheet = Sheet + 1
PlateHeight = 35
Call CreatePlate
End If
Next
SaltaTextOfPlate:
Next
If PlatesOnSheet < 5 Then
Copies = 5 - PlatesOnSheet
TextOfPlate = Application.InputBox(Copies & " blank plates remain: complete with?")
For HowMuch = 1 To Copies
Call CreatePlate
Next
End If
End Sub
Public Sub CreatePlate()
Set PPSlide = PPPresentation.Slides(Sheet)
Set Plate = PPSlide.Shapes.AddShape(Type:=msoShapeRectangle, Left:=61, Top:=PlateHeight, Width:=428.0315, Height:=144.5669)
With Plate.TextFrame.TextRange
.Text = TextOfPlate
.Font.Bold = True
.Font.Name = "Arial Narrow"
.Font.Size = 36
.Paragraphs.ParagraphFormat.Alignment = 2
End With
Plate.Line.Visible = True
Plate.Fill.ForeColor.RGB = RGB(255, 255, 255)
Plate.TextFrame2.VerticalAnchor = msoAnchorMiddle
PlatesOnSheet = PlatesOnSheet + 1
PlateHeight = PlateHeight + 144.5669
End Sub
【问题讨论】:
-
如果我理解正确,您是在将 Excel 图表嵌入到 Powerpoint 中,对吗?如果是这样,您为什么不直接复制粘贴链接图表?这样,您根本不需要 VBA。
-
顺便说一下,作为对那些审阅你的代码并且意大利语不流利的人的礼貌,你可以考虑使用英语变量名来编写你的代码。
-
不,我不必将图表从 excel 复制到 powerpoint。我更改了变量名称。
-
您可以将同一 Excel 的多个部分部署在您的 powerpoint 中。例如,您可以复制粘贴链接一个单元格,PowerPoint 用户将在该单元格中输入一个值。这将导致 excel 被更新,并且 powerpoint 中的结果也被更新。这只是一个想法。
标签: excel vba powerpoint