根据单元格值将Excel选项卡导出到Powerpoint幻灯片中

时间:2018-11-28 13:19:54

标签: excel vba excel-vba powerpoint

希望可以为您提供帮助。

完整的VBA新手,我已经搜索并寻找问题的答案,但找不到我想要的东西。

我所拥有的是一本工作簿,其中包含许多用于保存不同数据和叙述的选项卡。仅当这些选项卡的单元格“ CI8”大于0时,我才需要某种方法将这些工作表(打印视图区域)导出到单独的PowerPoint幻灯片中。例如,我具有名为“ RestWest”,“ RestCentre”,“ RestEast”,“ RestRS”的选项卡”,如果只有RestWest和RestRS的单元格CI8> 0,则只有这两张纸会放入Powerpoint。最好将其粘贴为图片。

我能够导出到PDF,但是像PowerPoint这样的高级管理人员更好。

希望您能提供帮助,并给我一些提示。

感谢您的时间

在将一张工作表拉入PowerPoint时应包含以下代码,但需要包含单元格值条件

Sub CopyRangeToPresentation()

    Dim pp As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide
    Dim SlideTitle As String
    Set pp = New PowerPoint.Application
    Set PPPres = pp.Presentations.Add
    pp.Visible = True
    Set PPSlide = PPPres.Slides.Add(1, ppLayoutTitleOnly)
    PPSlide.Select
    Sheets("RestWest").Range("A1:CV77").CopyPicture _
    Appearance:=xlScreen, Format:=xlPicture
    PPSlide.Shapes.Paste.Select
    pp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
    pp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
    SlideTitle = "My First PowerPoint Slide"
    PPSlide.Shapes.Title.TextFrame.TextRange.Text = SlideTitle
    pp.Activate
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set pp = Nothing
End Sub

1 个答案:

答案 0 :(得分:2)

TheSpreadsheetGuru - Copy & Paste An Excel Range Into PowerPoint With VBA

我也是新手,但是请查看此链接,然后尝试尝试以下操作:

For Each sht In Worksheets
With sht
    If .Range("CI8").Value2 > 0 Then
        .Range("Print_Area").Copy
        'use SpreadSheetGuru to show you how to insert new slide and paste
        ' ...
    End If
End With
Next
相关问题