VBA

2016-06-09 38 views
0

移動(剪切和粘貼)Powerpoint幻燈片與部分信息我正在尋找一種解決方案來選擇一些幻燈片和剪切或複製和粘貼在另一個位置,同時保持部分信息。 我已經看到PPT不支持開箱即用(請參閱http://answers.microsoft.com/en-us/office/forum/office_2013_release-powerpoint/copying-sections-to-a-new-powerpoint/2c723b0d-d465-4ab6-b127-6fdfc195478c?db=5) 並且還有一些VBA腳本示例Exporting PowerPoint sections into separate files PPTalchemy提供了一些插件,但不幸的是代碼不可用。看到這裏http://www.pptalchemy.co.uk/powerpoint_hints_and_tips_tutorials.html#2010VBA

此外,它不適合在同一個演示文稿中輕鬆移動節。

任何想法如何做到這一點?

非常感謝。 蒂埃裏

+0

當粘貼到不同的幻燈片索引位置時,您會發生什麼?如果粘貼到某個部分中,則無需執行任何操作(AFAIK,但需要檢查),但是如果粘貼到另一部分,您是否希望創建一個與源部分同名的新部分?你試圖達到什麼樣的需求? –

+0

好問題。我試圖實現的是移動多個部分(以及所有的幻燈片)。我會在「全部摺疊」部分視圖中執行此操作,或者在選擇之前的部分前粘貼。我希望能夠以這種方式重新組織我的演示文稿。想象一下,我的演示文稿中有第1部分,第2部分,第3部分,第4部分,第5部分,我想將其邏輯/結構更改爲第1部分,第4部分,第5部分,第2部分,第3部分。本案在第1部分之後或第2部分之前「移動」第4部分和第5部分。 –

回答

1

這是最後的code我用移動幻燈片選擇的多個部分:

Sub MoveSelectedSections() 
' Slides are copied ready to be pasted 
Dim lngNewPosition As Long 
'Debug.Print "" 
'Debug.Print "###Move Sections..." 
lngNewPosition = InputBox("Enter a destination section index:") 
lngNewPosition = CInt(lngNewPosition) ' Convert String to Int 
Call MoveSectionsSelectedBySlides(ActivePresentation, lngNewPosition) 

End Sub 


Function MoveSectionsSelectedBySlides(oPres As Presentation, lNewPosition As Long) 
    On Error GoTo errorhandler 

    ' Activate input presentation 
    oPres.Windows(1).Activate 

    ' Get Selected Sections Indexes 

    ' http://www.thespreadsheetguru.com/the-code-vault/2014/4/3/copy-selected-slides-into-new-powerpoint-presentation 

    Dim i, cnt As Integer 
    Dim SelectedSlides As SlideRange 
    Dim SectionIndexes() As Long 

    If ActiveWindow.Selection.Type <> ppSelectionSlides Then 
     MsgBox "No slides selected" 
     Exit Function 
    End If 

    Set SelectedSlides = ActiveWindow.Selection.SlideRange 
    ' selection order is reverse see http://www.pptfaq.com/FAQ00869_Create_a_custom_show_from_current_slide_selection_using_VBA.htm 


    'Fill an array with sectionIndex numbers 
    ReDim SectionIndexes(1 To SelectedSlides.Count) 
    cnt = 0 
    For i = 1 To SelectedSlides.Count 
    ' Check if already present in array 
     If Not Contains(SectionIndexes, SelectedSlides(i).sectionIndex) Then 
     cnt = cnt + 1 
     SectionIndexes(cnt) = SelectedSlides(i).sectionIndex 
     End If 
    Next i 
    ReDim Preserve SectionIndexes(1 To cnt) 


    ' Move Sections to lNewPosition, first last 
    For i = 1 To cnt 
     With oPres 
      .SectionProperties.Move SectionIndexes(i), lNewPosition 
     End With 
     Debug.Print "Section #" & SectionIndexes(i) & " moved to " & lNewPosition 
    Next i 



Exit Function 
errorhandler: 
    Debug.Print "Couldn't move section due to the following error: " & Err & ", " & Err.Description 
End Function 





Function Contains(arr, v) As Boolean 
' http://stackoverflow.com/a/18769246/2043349 
Dim rv As Boolean, i As Long ' Default value of boolean is False 
For i = LBound(arr) To UBound(arr) 
    If arr(i) = v Then 
     rv = True 
     Exit For 
    End If 
Next i 
Contains = rv 
End Function 
1

要將演示文稿中移動部分,包括部分中的所有幻燈片,請在致電段的指數這個過程被移動和它的新位置:

Option Explicit 

' ******************************************************************************** 
' VBA Macro for PowerPoint, written by Jamie Garroch of http://YOUpresent.co.uk/ 
' ******************************************************************************** 
' Purpose : Moves a specified section of slides to a new section location 
' Inputs : lSectionIndex - the index of the section to be moved 
'   lNewPosition - the index of the position to move to 
' Outputs : None. 
' ******************************************************************************** 
Public Sub MoveSection(lSectionIndex As Long, lNewPosition As Long) 
    On Error GoTo errorhandler 
    With ActivePresentation 
    .SectionProperties.Move lSectionIndex, lNewPosition 
    End With 
Exit Sub 
errorhandler: 
    Debug.Print "Couldn't move section due to the following error: " & Err & ", " & Err.Description 
End Sub