[英]Exporting data from Excel to an existing PowerPoint slide using VBA
[英]Copy Excel data to exact PowerPoint slide cell using VBA
因此,我有一个工作的宏,它将Excel行复制为图片,并将每张图片粘贴到新的PowerPoint幻灯片中。
因此,我现在的工作是从确切的单元格中获取单个数据(例如A1,D1,H1,X1)并将其粘贴到预定义的PowerPoint幻灯片布局中。 因此,每个单元格都将转到幻灯片布局中的相应位置。 我认为只需要一点修改,但是我绝对不知道该怎么做。 我对VBA真的很陌生,因此感谢所有帮助。
谢谢您的时间,祝您度过愉快的一天! :)
Sub CopyRangeToPresentation()
'Variables
Dim PP As PowerPoint.Application
Dim PPpres As PowerPoint.Presentation
Dim PPslide As PowerPoint.Slide
Dim SlideTitle As String
Dim lRow As Long
Dim i As Integer
'Fider
lRow = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
'New presentation
Set PP = New PowerPoint.Application
Set PPpres = PP.Presentations.Add
Set PP = GetObject(, "PowerPoint.Application")
PP.Visible = 1
For i = 1 To lRow
'New slide
Set PPslide = PPpres.Slides.Add(i, ppLayoutBlank)
PP.ActiveWindow.ViewType = ppViewSlide
PPpres.PageSetup.SlideSize = ppSlideSizeOnScreen
PP.ActiveWindow.WindowState = ppWindowMaximized
PPslide.Select
'Copy
Sheets("dataflows").Range(Cells(i, 1), Cells(i, 24)).CopyPicture _
Appearance:=xlScreen, Format:=xlPicture
'Paste
PPslide.Shapes.Paste.Select
PP.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PP.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
'Title
Next i
'Memory
PP.Activate
Set PPslide = Nothing
Set PPpres = Nothing
Set PP = Nothing
End Sub
您可以在所需单元格的位置使用文本框创建自定义布局。 文本框内的文本可用于标识它们(例如“ mybox1”)。 您可以通过Google搜索如何从自定义布局添加新幻灯片。 然后搜索形状并将单元格粘贴到相同的位置。 像这样:
'Paste
For Each PPshape In PPslide.Shapes
If PPshape.HasTextFrame Then
If PPshape.TextFrame.HasText Then
If PPshape.TextFrame.TextRange.Text = "mybox1" Then
PPslide.Shapes.Paste.Select
PP.ActiveWindow.Selection.ShapeRange.Left = PPshape.Left
PP.ActiveWindow.Selection.ShapeRange.Top = PPshape.Top
PPshape.Delete
End If
End If
End If
Next PPshape
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.