我使用宏将对象从PowerPoint导出到Excel。我有选择,选择目前开放的演示文稿,我想出口到。然而,当我切换演示文稿时,是否有办法阻止焦点从Excel切换到PowerPoint?我的代码如下:
Function SetActivePresentation(Filename As String) As Boolean
Dim i As Integer
' This just checks if PowerPoint is loaded - not needed for the question
If Me.Load = False Then
SetActivePresentation = False
End If
' Loop through the PowerPoint windows
For i = 1 To Me.pPowerpoint.Windows.Count
If Me.pPowerpoint.Windows(i).Presentation.name = Filename Then
Me.pPowerpoint.Windows(i).Activate
Exit For
End If
Next i
SetActivePresentation = True
End Function这是类中的pPowerPoint方法:
Public pPowerpoint As Object
Public Property Get PowerPoint() As Object
PowerPoint = pPowerpoint
End Property最后,我的负载函数:
Function Load() As Boolean
On Error Resume Next
' Set the PowerPoint object
Set pPowerpoint = GetObject(Class:="PowerPoint.Application")
' Handle if the PowerPoint Application is not found
If Err.Number = 429 Then
GoTo ErrorHandler
End If
Load = True
Exit Function
ErrorHandler:
Load = False
End Function然后从代码的其他地方导出Excel对象,方法是以For Each slide In PowerPoint.pPowerpoint.ActivePresentation.Slides的方式循环遍历For Each slide In PowerPoint.pPowerpoint.ActivePresentation.Slides幻灯片,其中PowerPoint是我在上面引用的PowerPoint类。
发布于 2016-12-02 02:35:37
..change是一种没有切换焦点的活动PowerPoint演示文稿,这有点让人困惑.但从上述讨论中可以看出,真正的问题是如何在导出 Excel对象时不使用聚焦。要解决这个问题,可以避免使用ActivePresentation对象。多么?一个简单的解决方案是使用全局变量。
下面的代码显示了它是如何完成的。
'Global variables
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
'searching for presentation (function/sub)
For i = 1 To Me.pPowerpoint.Windows.Count
If Me.pPowerpoint.Windows(i).Presentation.name = Filename Then
'dont activate! Me.pPowerpoint.Windows(i).Activate
Set pptPres = Me.pPowerpoint.Windows(i).Presentation
Exit For
End If
Next i
'copy object "Char 1" at "Sheet1"
'by accessing the global variable (other function/sub)
Set objChart = Worksheets("Sheet1").ChartObjects("Chart 1").Chart
objChart.ChartArea.Copy
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
pptSlide.Shapes.Pastehttps://stackoverflow.com/questions/40904985
复制相似问题