2017-04-20 27 views
0

我在玩一個進度條(基本上沒有任何VBA經驗)。我在網上找到以下代碼片段:VBA:選擇定義部分的所有幻燈片

Sub ProgressBar() 
    On Error Resume Next 
    With ActivePresentation 
    .SectionProperties.SlidesCount(
     For N = 2 To .Slides.Count 
     .Slides(N).Shapes("Progress_Bar").Delete 
     Set s = .Slides(N).Shapes.AddShape(msoShapeRectangle, 0, .PageSetup.SlideHeight - 10, N * .PageSetup.SlideWidth/.Slides.Count, 10) 
     Call s.Fill.Solid 
     s.Fill.ForeColor.RGB = RGB(128, 128, 128) 
     s.Line.Visible = False 
     s.Name = "Progress_Bar" 
     Next N: 
    End With 
End Sub 

請注意與For N = 2 To .Slides.Count部分。我希望進度條不能從第二張幻燈片到達最後一張,而是從第二張幻燈片到我稱爲「結論」的部分的最後一張幻燈片。我怎樣才能做到這一點?

謝謝!

編輯:我當前的解決方法是我在宏的開頭定義爲變量的幻燈片的硬編碼數量,然後在整個剩餘部分中使用該變量。

+0

嘗試改變'對於N = 2到.Slides.Count'到'對於N = 2到Selection.Slides.Count' – R3uK

+0

我想腳本是自動化的,所以我不必每次運行時都做相應的選擇。 –

+0

有一個名爲「sliderange」的幻燈片對象,代表「幻燈片」集合的一個子集。進一步的信息找到[這裏](https://msdn.microsoft.com/en-us/library/ff744720.aspx) –

回答

1

這裏有幾個位,應該讓你開始:

LastSlideOf返回命名段傳遞給它的最後一張幻燈片的幻燈片索引:

Function LastSlideOf(sSectionName As String) As Long 
    Dim x As Long 

    With ActivePresentation.SectionProperties 
     x = SectionIndexOf(sSectionName) 
     LastSlideOf = (.FirstSlide(x) + .SlidesCount(x)) - 1 
    End With 

End Function 

Function SectionIndexOf(sSectionName As String) As Long 
    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