2
我需要能夠從我的原始.ppt
中選定的幻燈片中創建新的.ppt
(PowerPoint演示文稿)。下面的宏將採取您當前選擇的任何幻燈片並將它們複製到一個新的.ppt
。我發現了以下很好的代碼來完成大部分工作。通過Power Point VBA中的複選框選擇特定的幻燈片
Private Sub NytPPT_Click()
'PURPOSE: Copies selected slides and pastes them into a brand new presentation file
'SOURCE: www.TheSpreadsheetGuru.com
Dim NewPPT As Presentation
Dim OldPPT As Presentation
Dim Selected_slds As SlideRange
Dim Old_sld As Slide
Dim New_sld As Slide
Dim x As Long, y As Long
Dim myArray() As Long
Dim SortTest As Boolean
'Set variable to Active Presentation
Set OldPPT = ActivePresentation
'Set variable equal to only selected slides in Active Presentation
Set Selected_slds = ActiveWindow.Selection.SlideRange
'Sort Selected slides via SlideIndex
'Fill an array with SlideIndex numbers
ReDim myArray(1 To Selected_slds.Count)
For y = LBound(myArray) To UBound(myArray)
myArray(y) = Selected_slds(y).SlideIndex
Next y
'Sort SlideIndex array
Do
SortTest = False
For y = LBound(myArray) To UBound(myArray) - 1
If myArray(y) > myArray(y + 1) Then
Swap = myArray(y)
myArray(y) = myArray(y + 1)
myArray(y + 1) = Swap
SortTest = True
End If
Next y
Loop Until Not SortTest
'Set variable equal to only selected slides in Active Presentation (in numerical order)
Set Selected_slds = OldPPT.Slides.Range(myArray)
'Create a brand new PowerPoint presentation
Set NewPPT = Presentations.Add
'Align Page Setup
NewPPT.PageSetup.SlideHeight = OldPPT.PageSetup.SlideHeight
NewPPT.PageSetup.SlideOrientation = OldPPT.PageSetup.SlideOrientation
NewPPT.PageSetup.SlideSize = OldPPT.PageSetup.SlideSize
NewPPT.PageSetup.SlideWidth = OldPPT.PageSetup.SlideWidth
'Loop through slides in SlideRange
For x = 1 To Selected_slds.Count
'Set variable to a specific slide
Set Old_sld = Selected_slds(x)
'Copy Old Slide
yy = Old_sld.SlideIndex
Old_sld.Copy
'Paste Slide in new PowerPoint
NewPPT.Slides.Paste
Set New_sld = Application.ActiveWindow.View.Slide
'Bring over slides design
New_sld.Design = Old_sld.Design
'Bring over slides custom color formatting
New_sld.ColorScheme = Old_sld.ColorScheme
'Bring over whether or not slide follows Master Slide Layout (True/False)
New_sld.FollowMasterBackground = Old_sld.FollowMasterBackground
Next x
End Sub
我需要做的,是選擇幻燈片複製 - 基於複選框。因此,例如,如果我選擇複選框1 = TRUE,它將創建幻燈片1,2和3.或者,如果我選中複選框2 =真,它可以選擇幻燈片3,4,5和6.所以,如果我選擇了它會創建幻燈片的兩個框= 1,2,3,4,5,6。刪除任何重複項。
我已經嘗試了很多,包括這個:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
ActivePresentation.Slides.Range(Array(1, 2, 3)).Select
Else
MsgBox "nothing"
End If
End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
ActivePresentation.Slides.Range(Array(3, 4, 5, 6)).Select
Else
MsgBox "nothing"
End If
End Sub
我得到的錯誤:幻燈片(未知成員):無效的請求。該視圖不支持選擇。
我不知道如何才能讓這個工作?任何幫助表示讚賞,我很新的VBA編碼。
謝謝,這看起來不錯 - 但我仍然不太明白如何使用它與複選框? – NoThanks
這些複選框控件在哪裏?在幻燈片上的表單或ActiveX內容上?如果在幻燈片上,我不會推薦使用它們,因爲它們會導致詳細的安全警告(如果這是考慮因素,則與Mac不兼容)。最好將CheckBoxX_Click宏分配給幻燈片中的形狀,通過插入/動作/鼠標單擊/運行宏 –