这将以编程方式复制 UI,但我想您不想这样做,因为它需要用户交互:
Application.CommandBars.ExecuteMso "BroadcastSlideShow"
两个半有用的链接可能会有所帮助,尽管正如 Patrick 指出的那样,似乎无法找到 [带有工作示例] 的文档:
Broadcast Methods & Properties on MSDN
请注意,“其他版本”链接中有 2010 年的较小子集。
Microsoft Community Discussion on Broadcast via VBA
我什至没有达到你的水平,我收到错误“对象'广播'的方法'开始'失败”。然后我通过 PowerPoint 2016 UI(幻灯片放映/在线演示)开始广播会话,然后在“即时”窗口中使用以下内容返回服务 URL:
?ActivePresentation.Broadcast.PresenterServiceUrl
它返回一个带有 asmx 文件引用的本地化域:
https://ie1-broadcast.officeapps.live.com/m/present_2_0.asmx
但是将它与 .Start 方法一起使用仍然返回相同的错误。我想知道是否需要做一些准备工作(如使用 UI 时所见),例如保存到 OneDrive 位置。
使用 PowerPoint 2016 (PC),我设法连接到 Present Online 服务并使用 WinAPIs 为 VBA 线程独立计时器启动幻灯片放映,以便在调用 UI 命令后按两次 ENTER 键来模拟单击CONNECT 按钮,然后是 START PRESENTATION 按钮(DoEvents 不能用作出现的 PowerPoint 窗口是模态的,并且执行永远不会返回到 VBA)。在连接和准备开始演示之间有一些准备时间,对于我简单的一张幻灯片来说,这不到 10 秒,但您可能需要更改 TimerProc 中的常量 ENTER2 strong> 程序基于您的内容。显然这有点命中注定(因为 SendKeys 使用和未知时间)所以我仍在寻找更好的机制。您还需要决定如何共享与会者 url,在此示例中该 URL 仅作为 Debug.Print 语句输出。只需运行 StartBroadcast 程序即可。
' ======================================================
' =========== PowerPoint VBA Standard Module ===========
' ======================================================
' Purpose : Starts a "Present Online" broadcast session.
' Prerequisites : Access to Present Online service.
' Platform : Tested with PowerPoint 2016 (PC) only.
' Author : Jamie Garroch of YOUpresent Ltd. 24JAN2017
' http:\\youpresent.co.uk
' References : None
' ======================================================
Option Explicit
#If VBA7 Then
Public TimerID As LongPtr
Public TimerCycles As LongPtr
#Else
Public TimerID As Long
Public TimerCycles As Long
#End If
#If VBA7 Then
Private Declare PtrSafe Function SetTimer Lib "user32" _
(ByVal hwnd As LongPtr, _
ByVal nIDEvent As LongPtr, _
ByVal uElapse As LongPtr, _
ByVal lpTimerFunc As LongPtr) As LongPtr
Private Declare PtrSafe Function KillTimer Lib "user32" _
(ByVal hwnd As LongPtr, _
ByVal nIDEvent As LongPtr) As LongPtr
#Else
Private Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
#End If
' Run this procedure to start the broadcast session
Sub StartBroadcast()
ActivePresentation.Windows(1).Activate
CommandBars.ExecuteMso "BroadcastSlideShow"
StartTimer
End Sub
Public Function StartTimer()
TimerID = SetTimer(0, 0, 1000, AddressOf TimerProc)
If TimerID = 0 Then Debug.Print "Timer not created.": Exit Function
Debug.Print "Timer " & TimerID & " started at : " & Now
End Function
Private Sub TimerProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal idEvent As Long, _
ByVal dwTime As Long)
TimerCycles = TimerCycles + 1
Debug.Print "Timer " & TimerID & " running : " & TimerCycles
' Number of seconds to wait before pressing ENTER the first time
' to simulate pressing the "CONNECT" button
Const ENTER1 = 1
' Number of seconds to wait before pressing ENTER the first time
' to simulate pressing the "START PRESENTATION" button
Const ENTER2 = 10
' Clicks the "CONNECT" button after ENTER1 seconds
If TimerCycles = ENTER1 Then SendKeys "{enter}"
' Clicks the "START PRESENTATION" button after ENTER2 seconds
If TimerCycles = ENTER2 Then SendKeys "{enter}"
' Output the Attendee URL for sharing and kill the timer
If TimerCycles > ENTER2 Then
Debug.Print ActivePresentation.Broadcast.AttendeeUrl
StopTimer
End If
End Sub
Public Function StopTimer()
#If VBA7 Then
Dim tmpTimerID As LongPtr
#Else
Dim tmpTimerID As Long
#End If
tmpTimerID = TimerID
TimerID = KillTimer(0, TimerID)
If TimerID = 0 Then
Debug.Print "Couldn't kill the timer"
Else
Debug.Print "Timer " & tmpTimerID & " stopped at : " & Now & " with " & TimerCycles & " cycles"
End If
TimerCycles = 0
TimerID = 0
End Function