演示文稿(x).Window(1)。激活不起作用

时间:2014-10-01 20:12:00

标签: vba

我已经写了一些vba代码来将幻灯片从一个演示文稿复制到另一个演示文稿。 我激活源演示文稿并复制幻灯片。 然后我切换到Destination-Presentation并执行PasteSpecial。 文件完成后,我保存目标演示文稿并关闭它。 来源也关闭了。 然后我循环到下一个文件并打开Source和Destination。 现在这适用于两个或三个文件。然后代码卡住了。 我在调试代码时资助的原因是激活目的地演示 突然不再工作了! 有什么想法发生了什么? 我正在使用PPT 2010和Win 7。 任何提示都将受到高度赞赏! 最好的祝福 汉斯

@TimWilliams 嗨蒂姆, 遵循代码中给我带来问题的部分。 看来,困难在于从源头到目的地的切换。从。切换 目的地来源始终有效。 实际上我写了宏来克服PPT-Handout格式的局限性, 图片通常太小,你不能将它们定位为左向和右向,以获得良好的双面打印输出。 这个宏基本上是基于“SlideCopy” - 微软的例子,它激发了我的尝试。

使用Do..Loop我开始打开源文件,然后是目标文件。 我从一个单独的(空)演示文稿中运行代码,只包含代码。总的来说,我将有3个演示文稿在运行。这只是代码中给我带来问题的部分。总代码有点大,因为我做了很多格式化,你可以想象。 无论如何 - 非常感谢您的兴趣! 汉斯

For x = 1 To SourceSlides                   'Loop through all the slides of Source and

ActivePresentation.Slides.Range(Array(x)).Select
ActivePresentation.Slides.Range(Array(x)).Copy  'Select the first slide in the presentation and copy it.

SourceCount = SourceCount + 1
Debug.Print "SourceCount = " & SourceCount

If SourceCount = 1 Then                         'window must be visible
    prDst.Windows(1).Activate                   ' Switch to destination presentation. <-- The problem!!
    oPpt.Visible = msoTrue
    ActiveWindow.View.GotoSlide (n)             'Switch to the proper slide.
    ActivePresentation.Slides(n).Shapes.PasteSpecial (ppPasteEnhancedMetafile)  ' Paste the slide as Shape

    If PasteLeftRight = 0 Then                  ' Adjust the size of the pasted object.
        ActivePresentation.Slides(n).Shapes(1).Select
        Paste_1_Right
    Else
        ActivePresentation.Slides(n).Shapes(1).Select
        Paste_1_Left
    End If

Else
    prDst.Windows(1).Activate       '<-- The other Problem!!
    oPpt.Visible = msoTrue

    ActiveWindow.View.GotoSlide (n) 'Index:=ActivePresentation.Slides.Count
    ActivePresentation.Slides(n).Shapes.PasteSpecial (ppPasteEnhancedMetafile)  ' Paste the slide.

    If PasteLeftRight = 0 Then                              ' Adjust the size of the pasted object.
        ActivePresentation.Slides(n).Shapes(2).Select
        Paste_2_Right
        PasteLeftRight = 1
    Else
        ActivePresentation.Slides(n).Shapes(2).Select
        Paste_2_Left
        PasteLeftRight = 0
    End If
    If x = SourceSlides Then
    Debug.Print "x = " & x
    Else
        ActivePresentation.Slides.Add _
        ActivePresentation.Slides.Count + 1, ppLayoutBlank
    End If

    SourceCount = 0
    n = n + 1

End If

' Unselect the object.
ActiveWindow.Selection.Unselect

' Switch to source.
prSrc.Windows(1).Activate
oPpt.Visible = msoTrue
If ActiveWindow.ViewType <> ppViewSlideSorter Then
   ActiveWindow.ViewType = ppViewSlideSorter
End If

Next x
.
.
.

0 个答案:

没有答案
相关问题