我正在一個項目上工作。在那我做了一個自定義的主題,其中包括一個主幻燈片和可能的佈局。 所以基本上我想將特定的佈局應用於特定的幻燈片。那麼有沒有什麼辦法可以通過編程來完成。 像:如何使用vba在PowerPoint中應用特定的佈局?
activepresentation.Slides(1).Layout = 「layoutname」
我知道上面的代碼是錯誤的,但我想這樣的事情由它的名字來稱呼特定佈局。爲了您的信息我的佈局名稱是「標題沒有客戶端標識」。
由於
我正在一個項目上工作。在那我做了一個自定義的主題,其中包括一個主幻燈片和可能的佈局。 所以基本上我想將特定的佈局應用於特定的幻燈片。那麼有沒有什麼辦法可以通過編程來完成。 像:如何使用vba在PowerPoint中應用特定的佈局?
activepresentation.Slides(1).Layout = 「layoutname」
我知道上面的代碼是錯誤的,但我想這樣的事情由它的名字來稱呼特定佈局。爲了您的信息我的佈局名稱是「標題沒有客戶端標識」。
由於
ActivePresentation.Slides(1).CustomLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(x)的
其中x是索引到佈局集合,表示自定義佈局。
與PPT OM中的大多數其他此類集合不同,這一個似乎無法接受索引或名稱。它必須是一個索引。
如果您需要使用該名稱,請編寫一個迭代CustomLayouts集合的函數,直到它找到您想要的名稱並返回索引。
使用下面的代碼
Sub ApplyLayoutByIndex()
Dim sld As Slide
Dim shp As Shape
Dim xName As String
Set sld = Application.ActiveWindow.View.Slide
Dim xIndex As Integer
xName = "A final slide"
xIndex = getLayoutIndexByName(xName)
If xIndex = 0 Then
MsgBox "The layout name" & xName & "not found. Check the name of the layout", vbOKOnly
Exit Sub
End If
sld.CustomLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(xIndex)
End Sub
Function getLayoutIndexByName(xName As String) As Integer
ActivePresentation.Designs(1).SlideMaster.CustomLayouts.Item (1)
With ActivePresentation.Designs(1).SlideMaster.CustomLayouts
For i = 1 To .Count
If .Item(i).Name = xName Then
getLayoutIndexByName = i
Exit Function
End If
Next
End With
End Function
謝謝!
嘿史蒂夫,其實我解決了我的問題。你是正確的功能是需要它的。我寫了它。謝謝你的評論。 – 2012-02-05 19:08:53
小心分享你的功能,@PratikGujarathi?我知道這很簡單,但它會爲未來的觀衆節省一些時間。 – sfarbota 2015-02-21 19:51:28