检查当前幻灯片的编号

时间:2015-06-30 16:30:05

标签: excel vba

我做了一个输入powerpoint的宏,遍历幻灯片,如果幻灯片有图表,它会打开它的优点并更改一些值。

但是我在特定幻灯片编号上执行特定功能时遇到问题,宏无法识别幻灯片编号并对每张幻灯片执行相同的操作。

这里有不完整的代码(我只是没有添加所有代码,因为它可能太长了):

'Iterate through slides
For Each sld In PowerPointApp.ActivePresentation.Slides

    With sld.Shapes(1)

        If .HasChart Then
            Set oPPChart = .Chart
            Set oPPChartData = oPPChart.ChartData

            oPPChartData.Activate

            'Set Excel objects
            Set oXlWb = oPPChartData.Workbook
            Set oXlApp = oXlWb.Parent

            Call CalcCopyPaste(oXlWb)
            Call DeleteColumnLastUsed(oXlWb)

            'Remover headers
            Select Case OPCountry

                Case "US"

                    'Remover headers só!
                    If sld = 8 Then

                        Range("U5").Select                            
                        Range(Selection, Selection.End(xlDown)).Select
                        Selection.Cut
                        Range("C3").Select
                        ActiveSheet.Paste


                    Else
                        Range("S3").Select
                        Range(Selection, Selection.End(xlToRight)).Select
                        Range(Selection, Selection.End(xlDown)).Select
                        Selection.Cut
                        Range("S1").Select
                        ActiveSheet.Paste

                    End If

            End Select

            oXlWb.Windows(1).Visible = False
            oXlApp.Visible = False

          End If

    End With

Next sld

因此,对于幻灯片8,它应该执行IF中所述的特定内容,但它会在每张幻灯片上完成所有操作! 你可以帮忙吗?谢谢!

1 个答案:

答案 0 :(得分:0)

正如BruceWayne所提议,我做了以下决定:

Select Case UCase(OPCountry)


            Case "US"
                'Conditions for slide 3, 4 and 5

                If sld.SlideNumber = 3 Or sld.SlideNumber = 4 Or sld.SlideNumber = 5 Or sld.SlideNumber = 6 Then

                    With sld.Shapes(1)

                        If .HasChart Then

                            Set oPPChart = .Chart
                            Set oPPChartData = oPPChart.ChartData

                            oPPChartData.Activate

                            'Set Excel objects
                            Set oXlWb = oPPChartData.Workbook
                            Set oXlApp = oXlWb.Parent

我刚刚将SlideNumber更改为我想要幻灯片的内容。我认为问题出在excel的编译器中,因为它(可能)已经打开了很多进程。