【问题标题】:Powerpoint 2010 - broadcast.start()PowerPoint 2010 - 广播.start()
【发布时间】:2017-06-08 17:27:18
【问题描述】:

我想创建一个 Powerpoint 幻灯片,它每 5 分钟自动从源更新一次,然后启动到网站的广播服务(并不断循环以刷新内容)。

我尝试使用下面的代码开始广播,但一直收到运行时错误: “客户端:将请求加载到 SoapReader 失败..”

Sub ShowIt()
    Application.ActivePresentation.SlideShowSettings.Run
    Application.ActivePresentation.Broadcast.Start ("https://bn1-broadcast.officeapps.live.com/")
    DoEvents
    End Sub

broadcast.start() 是如何工作的?

【问题讨论】:

  • msdn Presentation.Broadcast 属性没有太多文档,但是当我尝试您的代码时,我得到了登录提示。如果您没有它,我猜存储的凭据已过期,因此您会收到该错误。基本上,无论您的演示文稿显示什么,您都在提供该网址。完成后您还应该添加.Broadcast.End

标签: vba powerpoint powerpoint-2010


【解决方案1】:

这将以编程方式复制 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

【讨论】:

  • 您好 Jamie,非常感谢您在上面的回答。它运作良好。我开始意识到每次运行时它显示的 url 都会改变,因为我需要一个静态地址。
  • 我的整个项目正在获取一些动态数据,将其导入 Excel,然后将其转换为图表(每 5 分钟一次)。然后我希望能够在线直播/流式传输它。 Powerpoint 可以链接到 Excel 获取图表,但不能在不结束广播的情况下更新。如果每次我有一个新的网址,我将无法将它流式传输到最终用户的同一个位置。
  • 是的,广播是基于会话的,因此会话 ID 和与会者 URL 对于每个广播会话都是唯一的。您可以尝试使用 DataPoint 插件在幻灯片放映期间动态更新您的内容。我已经很多年没有使用它了,但对公司的产品印象深刻(我与他们没有任何关系)。 presentationpoint.com/software/datapoint
猜你喜欢
  • 2011-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多