[英]Copying a chart from Excel to PowerPoint and keeping the Source Formatting using VBA
[英]Copying the Data from Excel to PowerPoint table using VBA
讓我向您解釋我要做什么,然后再向您解釋我遇到的困難
->對於包含數據的每一行,將數據從Excel表復制到PowerPoint表(它們都有相同的標題)
->如果PowerPoint中的表格超過一定高度,則應開始將數據粘貼到新幻燈片上
所以,這就是我正在接近的方式:
->首先,將ppt中的一張幻燈片作為主幻燈片,其中表格具有標題,並在其下面有一個空白行-我將復制此幻燈片並將其粘貼到下一張幻燈片中
->從Excel復制每行並將其粘貼到PowerPoint表中
->如果PowerPoint中的表格跨過特定高度,則粘貼新的主幻燈片(我已將其復制)
->此循環應在Excel中包含數據的每一行繼續進行。
我正在一點一點地接近它。 到目前為止,我已經創建了一個循環,用於將行插入.ppt表中,並在幻燈片超過表高度限制時粘貼幻燈片。 但是我被困在這里-下面給出的循環僅針對主幻燈片插入行,並粘貼下一張幻燈片,但不插入其他幻燈片。
Public Sub Excel_cpy_pst()
Dim oTbl As Table
Dim mShp As ShapeRange
Dim shp As Object
Dim sldCount As Slide
Set sldCount = ActivePresentation.Slides(ActivePresentation.Slides.Count)
ActivePresentation.Slides(6).Copy 'Copying and using it as a master slide
Set mShp = ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes.Range(Array("MyShape"))
Set oTbl = mShp.Table
For Each shp In ActivePresentation.Slides
If mShp.Height <= 6.34 * 72 Then
With oTbl
.Rows.Add (-1) 'adding a row at the bottom of a table
End With
ElseIf ActivePresentation.Slides.Count <= 8 Then 'to stop it from infinite loop, putting a constatnt
With ActivePresentation.Slides
ActivePresentation.Slides.Paste (ActivePresentation.Slides.Count + 1)
End With
End If
Next
End Sub
如果從復制主幻燈片開始,則可以將新幻燈片分配給可以引用的變量。
Dim aSLide as Powerpoint.SlideRange
Set aSlide = .Slides("Slide1").Duplicate
with aSlide
for each shp in aslide.shapes
將此添加到循環中以引用原始幻燈片的新副本。
如果幻燈片模板(slide1)構造為表格,則可以將文本分配給表格中的每個單元格,然后移至下一張幻燈片,而無需檢查大小。 隨您所願,只需填寫方框即可。
祝好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.