通过VBA将Excel表中的单元格文本粘贴到PowerPoint中的形状中

时间:2019-07-05 11:41:06

标签: excel vba powerpoint

我想将信息从Excel表粘贴到PowerPoint(PPT)。此处B列表示“ 20XXYY”。这里的“ XX”表示年份,“ YY”表示一年(1到52)中的星期数。我在表中应用了条件格式,该条件格式是当前日期将变为红色之前的任何格式。我想将经过过滤的信息粘贴到PPT中的矩形中。例如,在一个特定的星期我们有多少个项目(见图1)。

Picture 1

不幸的是,我只能用桌子创建幻灯片(见图2)。

Picture 2

我还附上了我编写的代码。请参见下文

Sub Slidecreation()

Dim pptName As String
Dim ppt As PowerPoint.Application
Dim myPres As PowerPoint.Presentation
Dim slds As PowerPoint.Slides
Dim sld As PowerPoint.slide
Dim pptextbox As PowerPoint.Shape
Dim oLayout As CustomLayout
Dim wb As Workbook
Dim ws As Worksheet
Dim r As Range
Dim lastRw As Long
Dim y As Workbook

Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")

'This will open a PowerPoint template (I didn't attach the function)
pptName = openDialog()
Set ppt = CreateObject("PowerPoint.Application")
Set myPres = ppt.Presentations.Open(pptName)
Set slds = myPres.Slides
Set sld = ppt.ActivePresentation.Slides.Add(ppt.ActivePresentation.Slides.Count + 1, ppLayoutBlank)
lastRw = ws.Range("B" & Rows.Count).End(xlUp).Row
Set r = ws.Range("$A$1:$B" & lastRw)
r.Copy
sld.Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=msoFalse
sld.Shapes(1).Height = 600
sld.Shapes(1).Width = 300

End Sub

如何创建图片中显示的幻灯片1?创建单个文本框而不是形状将是一个很好的解决方案。因为动态更改形状大小会使此问题更加复杂。文本框/形状的位置不重要

关于, 奥利弗

0 个答案:

没有答案