0
我使用宏来将对象导出到Excel中的PowerPoint。我可以选择要导出到哪个当前打开的演示文稿。但是,当我切换演示文稿有没有办法停止从Excel到PowerPoint的焦点切换?我的代码如下:从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
然后从其他地方在我的代码和我可以通过以这种方式在PowerPoint幻灯片中循环导出Excel对象For Each slide In PowerPoint.pPowerpoint.ActivePresentation.Slides
,其中PowerPoint
是我上面引用的PowerPoint类。
你有什么需要通过'switching','Activating'?据我所知,大多数行为都不需要激活PP。你在代码的其他部分做了什么? –
@KazimierzJawor因为那时我可以调用'ActivePresentation'对象并导出Excel对象 –
您只需使用pPowerpoint作为前缀。 –