【问题标题】:Copy table from Excel to PowerPoint VBA将表格从 Excel 复制到 PowerPoint VBA
【发布时间】:2016-11-02 13:41:40
【问题描述】:

我正在尝试使用 VBA 将包含形状的表格从 Excel 工作表复制并粘贴到 PowerPoint 幻灯片中,并保持其源格式 []。 我想粘贴后直接写在幻灯片上的故事上。除了形状没有粘贴到表格中之外,一切似乎都运行良好 []。

Sub CreatePP()
    Dim ppapp As PowerPoint.Application
    Dim ppPres As PowerPoint.Presentation
    Dim ppSlide As PowerPoint.Slide
    Dim ppTextBox As PowerPoint.Shape
    Dim iLastRowReport As Integer
    Dim sh As Object
    Dim templatePath As String

        On Error Resume Next
        Set ppapp = GetObject(, "PowerPoint.Application")
        On Error GoTo 0

    'Let's create a new PowerPoint
        If ppapp Is Nothing Then
            Set ppapp = New PowerPoint.Application
        End If
    'Make a presentation in PowerPoint
        If ppapp.Presentations.Count = 0 Then
           Set ppPres = ppapp.Presentations.Add
           ppPres.ApplyTemplate "C:\Users\luunt1\AppData\Roaming\Microsoft\Templates\Document Themes\themevpb.thmx"
        End If

    'Show the PowerPoint
        ppapp.Visible = True

         For Each sh In ThisWorkbook.Sheets
         If sh.Name Like "E_KRI" Then
            ppapp.ActivePresentation.Slides.Add ppapp.ActivePresentation.Slides.Count + 1, ppLayoutBlank
            ppapp.ActiveWindow.View.GotoSlide ppapp.ActivePresentation.Slides.Count
            Set ppSlide = ppapp.ActivePresentation.Slides(ppapp.ActivePresentation.Slides.Count)
            ppSlide.Select


            iLastRowReport = Range("B" & Rows.Count).End(xlUp).Row
            Range("A1:J" & iLastRowReport).Copy
            DoEvents
            ppapp.CommandBars.ExecuteMso ("PasteExcelTableSourceFormatting")
            Wait 3
            With ppapp.ActiveWindow.Selection.ShapeRange
              .Width = 700
              .Left = 10
              .Top = 75
              .ZOrder msoSendToBack
            End With
            Selection.Font.Size = 12
          'On Error GoTo NoFileSelected
            AppActivate ("Microsoft PowerPoint")
            Set ppSlide = Nothing
            Set ppapp = Nothing
    End If
    Next   
End Sub

Private Sub Wait(ByVal nSec As Long)
    nSec = nSec + Timer
    While nSec > Timer
        DoEvents
    Wend
End Sub

【问题讨论】:

  • 那些椭圆形是手动放在excel表格上的吗?
  • 是的。你有什么办法解决吗?请帮帮我
  • 如果它们是手动放置的,即没有链接到单元格,那么解决方案将不是一件容易的事。您将需要循环浏览对象,找到它们的位置,然后确定 powerpoint 表上的相对位置以将它们放置在那里

标签: vba excel powerpoint shape


【解决方案1】:

而不是选择表格的范围并粘贴,它可能会解决您的解决方案,而不是粘贴表格对象本身,所以:

ActiveSheet.ListObjects(1).Copy  'Assuming it is the only table on the sheet.  Adjust this code as needed for your specific case

【讨论】:

    猜你喜欢
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 2015-06-12
    • 2011-04-19
    • 2023-02-08
    • 1970-01-01
    • 2015-02-06
    相关资源
    最近更新 更多