Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VBA Word webbrowser
hi,
i try to read a word document in a webbrower (VBA code with Word Application) but the document is opened outside the userform:
ex1: webbrowser1.Navigate "D:\TEST.doc" = not ok
ex2: webbrowser1.Navigate "D:\TEST.htm" = ok (in the userform)
 
Someone has the solution ?
thanks
Posted 8-Dec-12 23:42pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

As per MSDN Example[^] :- Wink | ;)
 
Imports System
Imports System.Windows.Forms
Imports System.Security.Permissions
 
<permissionset(securityaction.demand,> _
<system.runtime.interopservices.comvisibleattribute(true)> _
Public Class Form1
    Inherits Form
 
    Private webBrowser1 As New WebBrowser()
    Private WithEvents button1 As New Button()
 
    <stathread()> _
    Public Shared Sub Main()
        Application.EnableVisualStyles()
        Application.Run(New Form1())
    End Sub 
 
    Public Sub New()
        button1.Text = "call script code from client code"
        button1.Dock = DockStyle.Top
        webBrowser1.Dock = DockStyle.Fill
        Controls.Add(webBrowser1)
        Controls.Add(button1)
    End Sub 
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
        Handles Me.Load
 
        webBrowser1.AllowWebBrowserDrop = False
        webBrowser1.IsWebBrowserContextMenuEnabled = False
        webBrowser1.WebBrowserShortcutsEnabled = False
        webBrowser1.ObjectForScripting = Me 
        ' Uncomment the following line when you are finished debugging. 
        'webBrowser1.ScriptErrorsSuppressed = True

        webBrowser1.DocumentText = _
            "<html><head><script>" & _
            "function test(message) { alert(message); }" & _
            "</script></head><body><button hold=" />            " onclick=""> " & _
            "call client code from script code</button>" & _
            "</body></html>" 
    End Sub 
 
    Public Sub Test(ByVal message As String)
        MessageBox.Show(message, "client code")
    End Sub 
 
    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
        Handles button1.Click
 
        webBrowser1.Document.InvokeScript("test", _
            New String() {"called from client code"})
 
    End Sub 
 
End Class
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 265
1 CPallini 235
2 OriginalGriff 233
3 Maciej Los 195
4 George Jonsson 170
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 9 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100