我想用VBA代码在PPT的一幅幻灯片中插入一个Microsoft Web Browser,并显示google网页。请教大家怎么写代码,谢谢。

解决方案 »

  1.   

    本帖最后由 supergreenbean 于 2009-05-31 13:46:33 编辑
      

  2.   

    非常感谢!"Shell.Explorer.2"确实工作,我还有个问题,我做了个插件,功能是点击Insert/AddWebSlide时,加入一个新幻灯片,当预览时web browser自动导航至google。
    问题1)现在的代码当预览时不能正确自动导航,需要怎么办?
       2)我本想在当前页前插入新页,怎么获取当前是第几页?(现在是插入在第一页)希望能帮助我,再次感谢!下面是我的代码:Sub AddSlide()
            Dim s1 As Slide
            'Add new slide
            ActivePresentation.Slides.Add 1, ppLayoutTitleOnly
            Call AddWebBrowserEnd SubSub AddWebBrowser()
        Dim shp As Shape
        Set shp = Application.ActivePresentation.Slides(1).Shapes.AddOLEObject(100, 100, 400, 500, "Shell.Explorer.2")
        If Not shp Is Nothing Then
            shp.OLEFormat.Object.Navigate2 "http://www.g.cn"
        End If
    End SubSub Auto_Open()
    MsgBox "Auto open"
          Dim NewControl As CommandBarControl      ' Store an object reference to a command bar.
          Dim ToolsMenu As CommandBars      ' Figure out where to place the menu choice.
          Set ToolsMenu = Application.CommandBars      ' Create the menu choice. The choice is created in the first
          ' position in the Tools menu.
          Set NewControl = ToolsMenu("Insert").Controls.Add _
                           (Type:=msoControlButton, _
                            Before:=1)      ' Name the command.
          NewControl.Caption = "AddWebSlide"      ' Connect the menu choice to your macro. The OnAction property
          ' should be set to the name of your macro.
          NewControl.OnAction = "AddSlide"   End SubSub Auto_Close()      Dim oControl As CommandBarControl
          Dim ToolsMenu As CommandBars
    MsgBox "Auto close"
          ' Get an object reference to a command bar.
          Set ToolsMenu = Application.CommandBars      ' Loop through the commands on the tools menu.
          For Each oControl In ToolsMenu("Insert").Controls            ' Check to see whether the comand exists.
                If oControl.Caption = "AddWebSlide" Then              ' Check to see whether action setting is set to ChangeView.
                  'If oControl.OnAction = "AddSlide" Then                  ' Remove the command from the menu.
    MsgBox "delete one"
                      oControl.Delete
                   'End If
                End If
          Next oControl
       End Sub
      

  3.   

    在当前页插入新的页:
    Sub AddSlide()
        'Add new slide
        ActivePresentation.Slides.Add ActiveWindow.View.Slide.SlideIndex, ppLayoutTitleOnly
        Call AddWebBrowser
    End Sub
      

  4.   

    如果是在新的页中插入WebBrowser,则:
    Sub AddSlide()
        Dim sd As Slide, shp As Shape
        'Add new slide
        Set sd = ActivePresentation.Slides.Add(ActiveWindow.View.Slide.SlideIndex, ppLayoutTitleOnly)
        Set shp = sd.Shapes.AddOLEObject(100, 100, 400, 500, "Shell.Explorer.2")
        If Not shp Is Nothing Then
            shp.OLEFormat.Object.Navigate2 "http://www.google.cn"
        End If
    End Sub
    另外,我这儿预览时导航没有问题。
      

  5.   

    Sub AddSlide() 
        Dim sd As Slide, shp As Shape 
        'Add new slide 
        Set sd = ActivePresentation.Slides.Add(ActiveWindow.View.Slide.SlideIndex, ppLayoutTitleOnly) 
        Set shp = sd.Shapes.AddOLEObject(100, 100, 400, 500, "Shell.Explorer.2") 
        If Not shp Is Nothing Then 
            shp.OLEFormat.Object.Navigate2 "http://www.google.cn" 
        End If 
    End Sub 
      

  6.   

    在第二张幻灯片的(0,0)位置插入一个100x100的webbrowser控件,并导航至google 
      

  7.   

    比较新鲜的,我对VB不怎么熟悉,但Java还可以,如果用Java做,应该如何呀?!
      

  8.   

    VB code    Dim shp As Shape 
        Set shp = Application.ActivePresentation.Slides(2).Shapes.AddOLEObject(0, 0, 100, 100, "Shell.Explorer.2") 
        If Not shp Is Nothing Then 
            shp.OLEFormat.Object.Navigate2 "http://www.g.cn" 
        End If 
     
    豆豆厉害,学习!