1

I created a simple macro to put an HTML widget from Weather.com in to a PowerPoint slide.

It is not event-based, but ActionButtons call the ConnectWidget subroutine, when navigating to the slide. That's working fine, but you will notice that I have only been able to get this to work by first deleting the existing WebBrowser shape, and then re-creating it.

I had to do this, ultimately, because any method call from wb after the .Navigate, I get an Automation Error/Unspecified Error, or Method unavailable error. So for example, I could not call on wb.Refresh when moving back and forth between slides, without first deleting the browser shape entirely, and recreating it.

There is probably something obvious that I am overlooking -- any thoughts to what might be causing those errors? Google turned up nothing really useful in resolving the problem.

Sub ConnectWidget()
    Dim sld As Slide
    Dim pres As Presentation
    Dim shp As Shape
    Dim wb As IWebBrowser2
    Dim fname As String: fname = "c:" & Environ("homepath") & "\widget2.html"
    Set pres = ActivePresentation
    Set sld = pres.Slides(2)

    On Error Resume Next
    sld.Shapes("weatherwidget").Delete
    On Error GoTo 0

    If Len(Dir(fname)) = 0 Then CreateHTML fname

    Set shp = sld.Shapes.AddOLEObject(100, 200, 200, 150, _
        "Shell.Explorer.2")
    shp.Name = "weatherwidget"
    Set wb = sld.Shapes("weatherwidget").OLEFormat.Object

    With wb
        .Navigate (fname)
    End With

    ' wb.Refresh  '## UNCOMMENT THIS LINE AND YOU WILL GET AN ERROR

    Set wb = Nothing
    On Error Resume Next
    Kill fname
    On Error GoTo 0

End Sub

Private Sub CreateHTML(fileName$)
    'Createsa plaintext HTML file that IWebBrowser2 can navigate
    '<script type="text/javascript" src="http://voap.weather.com/weather/oap/90210?template=GENXH&par=3000000007&unit=0&key=twciweatherwidget"></script>
    Dim htmlTxt As String
    Dim fs As Object
    Dim a As Object
    htmlTxt = "<script type=" & Chr(34) & "text/javascript" & Chr(34) & "src=" & Chr(34) & _
            "http://voap.weather.com/weather/oap/90210?template=GENXH&par=3000000007&unit=0&key=twciweatherwidget" _
            & Chr(34) & "></script>"

        Set fs = CreateObject("Scripting.FileSystemObject")
        Set a = fs.CreateTextFile(fileName, True)
        a.WriteLine htmlTxt
        a.Close

End Sub

Here is one such error. Note that I have no option to Debug the error. All I can surmise from stepping over the code is that any method call after the .Navigate will result in this error.

enter image description here

David Zemens
  • 53,033
  • 11
  • 81
  • 130
  • just to be sure- you are not interested in placing WebBrowser in Slide manually and only control navigation and refreshment from VBA? that could work quite stable... you need to create everything from the scratch based on VBA? – Kazimierz Jawor Jun 07 '13 at 23:21
  • I had initially created the browser object manually. Then, I discovered that it was causing errors when I would try to refresh the content, or if I advance the SlideShow to the next slide, and then return to the slide with the browser, it would be empty, etc. If it is possible to easily control the `.Refresh` and `.Navigate`, then I am obviously missing something :) – David Zemens Jun 08 '13 at 00:20

0 Answers0