I'm wanting to create a Powerpoint slide that automatically updates from a source every 5 mins then starts a broadcast service to a website (& keeps looping to refresh the content).
I've tried using this code below to start broadcasting, but keep getting a run time error: "Client: Loading the request into SoapReader failed.."
Sub ShowIt()
Application.ActivePresentation.SlideShowSettings.Run
Application.ActivePresentation.Broadcast.Start ("https://bn1-broadcast.officeapps.live.com/")
DoEvents
End Sub
How does broadcast.start() work?
This will replicate the UI programmatically but I guess you don't want to do this as it requires user interaction:
Application.CommandBars.ExecuteMso "BroadcastSlideShow"
Two semi-useful links which might help although as PatricK points out, documentation [with working examples] seem to be impossible to find:
Broadcast Methods & Properties on MSDN Note that there is a smaller subset for 2010 in the Other Versions link.
Microsoft Community Discussion on Broadcast via VBA
I didn't even get as far as you and I get the error "Method 'Start' of object 'Broadcast' failed". I then started the broadcast session via the PowerPoint 2016 UI (Slide Show / Present Online) and then used the following in the Immediate window to return the service URL:
?ActivePresentation.Broadcast.PresenterServiceUrl
It returned a localised domain with an asmx file reference:
https://ie1-broadcast.officeapps.live.com/m/present_2_0.asmx
But using that with the .Start method still returned the same error. I'm wondering if some preparation needs to be done (as seen when using the UI) such as saving to a OneDrive location.
Using PowerPoint 2016 (PC), I managed to connect to the Present Online service and start the slide show using WinAPIs for VBA thread independent timers so that the ENTER key is pressed twice after invoking the UI command to simulate the clicking of the CONNECT button and then the START PRESENTATION button (DoEvents can't be used as the PowerPoint windows that appear are modal and execution never returns to VBA). There is some preparation time between connecting and being ready to start the presentation which for my simple one slide deck was just under 10 seconds but you might need to change the constant ENTER2 in the TimerProc procedure based on your content. Obviously this is a bit hit and miss (because of SendKeys use and unknown times) so I'm still looking for a better mechanism. You'll also need to decide how to share the attendee url which is just output as a Debug.Print statement in this example. Just run the StartBroadcast procedure.
' ======================================================
' =========== 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.