【问题标题】:Transpose paste copied range from Excel to PowerPoint Charts将复制的范围从 Excel 转置到 PowerPoint 图表
【发布时间】:2017-05-05 13:52:42
【问题描述】:

我正在尝试使用 excel 中的数据更新我的一些幻灯片,并使用以下代码将其粘贴到 PowerPoint 图表后端。

Sub updateSlides()
  Application.DisplayAlerts = False
  Dim xlApp, xlWorkBook, xlSheet As Object

  Set xlApp = CreateObject("Excel.Application")
  ' Not transposing
  xlApp.DisplayAlerts = Flase
  xlApp.Visible = True

  Set xlWorkBook = xlApp.Workbooks.Open("ExcelFilePath")
  Set xlSheet = xlWorkBook.Sheets("SheetName")

  For i = 1 To 9
    With ActivePresentation.Slides(i)
      Set charts = .Shapes("Chart 37").Chart.ChartData
      charts.Activate
      Set chartData = charts.Workbook.Sheets("Sheet1")
      xlSheet.Range(xlSheet.Cells(2 + i, 2), xlSheet.Cells(2 + i, 3)).copy
      chartData.Range("B8").PasteSpecial Paste:=-4163
      ' I need to transpose the copied data here'
      charts.Workbook.Close
    End With
   If i < 9 Then
      ActiveWindow.View.GotoSlide Index:=ActiveWindow.Selection.SlideRange.Duplicate.SlideIndex
    End If
  Next i

  xlApp.Quit
  xlApp.DisplayAlerts = True
  Set xlApp = Nothing

  ' ActivePresentation.Save

  Application.DisplayAlerts = True

End Sub

在第 20 行,我需要转置复制的数据并将其粘贴到提供的目标范围。 任何帮助都将不胜感激。

【问题讨论】:

    标签: vba excel powerpoint


    【解决方案1】:

    尝试使用Transpose 参数:

    chartData.Range("B8").PasteSpecial Paste:=-4163, Transpose:=True
    

    同时纠正错字:

    xlApp.DisplayAlerts = False ' <--- Not Flase
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-11
      • 1970-01-01
      • 2015-10-14
      • 2015-03-10
      • 2016-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多