使用 VBA 从 Excel 单元格中提取数据到 PowerPoint 形状

Extract Data from Excel Cell to PowerPoint Shape with VBA

我有一个 excel 工作簿,第一栏是儒略日,第二栏是正常高温,第三栏是正常低温。我需要在 PowerPoint VBA 中编写一个脚本,以将当前儒略日与工作簿第一列中的相同数字相匹配。然后我需要它提取当天的正常高点(第二列)并将该数字插入到特定 PPT 幻灯片中的命名形状中。这是我目前所拥有的:

Function SectionIndexOf(sSectionName As String) As Long
'This Function makes sure you can declare the name of any Section Name
'in the Sub below.

    Dim x As Long
    With ActivePresentation.SectionProperties
        For x = 1 To .Count
            If .Name(x) = sSectionName Then
                SectionIndexOf = x
            End If
        Next
    End With
End Function

Sub Climo()

Headlines = SectionIndexOf("Headlines")

'Open the Excel Workbook.
Dim CLI As New Excel.Workbook
Set CLI = Excel.Application.Workbooks.Open("Z:\climo.xlsx")

'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Dim NormalHi As String
Dim NormalLo As String
Dim shp As Shape
Dim sld As Slide

Set WS = CLI.Worksheets(1)

Dim i As Long
'Loop through all rows in Column A (Julian Day)

For i = 1 To WS.Range("A372").End(xlUp).Row
    NormalHi = WS.Cells(i, 9).Value
    Debug.Print NormalHi 'This just returns new blank lines

    For Each sld In ActivePresentation.Slides
        For Each shp In sld.Shapes
            If sld.sectionIndex = Headlines Then
                With sld.Shapes("NormalHi")
                .TextFrame2.TextRange.Font.Name = Arial
                .TextFrame2.TextRange.Font.Size = 16
                .TextFrame.TextRange.Font.Color = vbRed
                .TextFrame2.TextRange.Text = NormalHi
                End With
            End If
        Next
    Next
Next

End Sub

在尝试弄清楚如何将当前儒略日与 Excel 工作簿中的正确行相匹配之前,我只是想从任何单元格中提取数据并将其绘制在形状中。当我 运行 并使用 Debug.Print 给我空白的新行时,我没有得到任何错误。不知道哪里出了问题。谢谢!

您在问题中提到在第 2 列中找到了 Normal High 数据,但是当您获取该值时,您引用的是第 9 列。也许这就是问题所在?

NormalHi = WS.Cells(i, 9).Value