将更多的powerpoint演示文稿加入到一个新的演示文稿中,保留Lotusscript中最初的幻灯片布局

时间:2012-10-01 11:47:26

标签: powerpoint-vba

我正在开发一个项目,将两个或更多pp演示文稿连接到一个新的演示文稿中。 原始pp演示文稿的选择在基于Web的Lotus Notes xPage中,在提交之后,Lotusscript与OLE Powerpoint对象进行对话。 以正确的顺序将幻灯片添加到新演示文稿中是没有问题的。 问题是在使用幻灯片添加原始连接后,模板将丢失。

为了解决这个问题,我找到了下一个代码片段:

Sub joiner()
 Dim sFileName As String
 Dim oDonor As Variant
 Dim otarget As Variant
 Dim i As Integer
 On Error GoTo errhandler

 Set otarget = ActivePresentation

 Do While sFileName <> ""
 Set oDonor = Presentations.Open(Environ("USERPROFILE") & "\Desktop\joiner\" &     sFileName, msoFalse)

 For i = 1 To oDonor.Slides.Count
 oDonor.Slides(i).Copy

 With otarget.Slides.Paste(otarget.Slides.Count + 1)
 .Design = oDonor.Slides(i).Design
 .ColorScheme = oDonor.Slides(i).ColorScheme
 End With

 Next i

 oDonor.Close
 Set oDonor = Nothing
 sFileName = Dir()
 Loop

 End Sub

我必须将演示文稿oDonor和oTarget声明为变体,因为lotusscript不理解Dim oTarget As Presentation

这可能是代码在以下位置返回typemismatch错误的原因: .Design = oDonor.Slides(i).Design

我的问题是:

  1. 我是以正确的方式进行加入还是有更好的解决方案?
  2. 是否有针对typemismatch错误的解决方案?
  3. * ps:结果演示文稿不必是可编辑的,因此可能没有必要添加模板。

    2012年4月10日更新: 下一个代码解决了模板问题。 现在仍然缺少的是一些幻灯片使用的背景图像。 请参阅:https://stackoverflow.com/questions/12731691/how-to-export-a-backgroundimage-of-a-slide-to-the-filesystem

    Dim oDonor As Variant
    Dim h As Integer
    Dim thetmplt As Variant
    Dim thetmpltname As String
    Dim thetmpltnew As Variant
    Dim thetmpltnamenew As String
    
    Set oDonor = PPApplication.Presentations.Open(tempdirectory +
    jobid+CStr(filenamearray  (i)),False,False,False)
    
    thetmplt = oDonor.TemplateName  
    Call oDonor.SaveAs(tempdirectory +jobid+CStr(i)+ thetmplt+".pot" ,5, -1)
    
    For h = 1 To oDonor.Slides.Count
    
    Dim oTargetSlide As Variant         
    
    oDonor.Slides(h).Copy
    Set oTargetSlide =  newPres.Slides.Paste()
    
    
    Next        
    
    Dim theubound As Variant
    theubound = oDonor.Slides.Count
    ReDim thearray(1 To k + theubound) As Variant
    
    
    For k = k To k + oDonor.Slides.Count-1
    
    thearray(k) = k
    Next
    
    Call newPres.Slides.Range(thearray()).ApplyTemplate(tempdirectory +
    jobid+CStr(i+thetmplt+".pot")
    
    oDonor.Close
    Set oDonor = Nothing
    

1 个答案:

答案 0 :(得分:0)

这只是一种预感,但请尝试:

Dim oTargetSlide as Variant
Set oTargetSlide =  otarget.Slides.Paste(otarget.Slides.Count + 1)(1)
With oTargetSlide
 .Design = oDonor.Slides(i).Design
 .ColorScheme = oDonor.Slides(i).ColorScheme
 End With