Solved

Using webBrowser to display word docs:

Posted on 2002-03-17
20
145 Views
Last Modified: 2012-08-13
Normally I use
"webBrowser1.navigate  ///C:\Windows\Desktop\Phones.doc"
- if the Phones.doc file is password protected (lets say that the password is "MyPwd"),
how should I pass the password to the file so that I will not be promped for password?
It works well when I use "SendKeys",but I am looking for a better solution.

Please, show me some other ways to open the password protected doc file  with WebBrowser.
0
Comment
Question by:givatada
  • 10
  • 9
20 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
wait...
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
I use a similar approach to log in Lotus Notes email client. You could try, see:
www.angelfire.com/realm/vb-shared/index.html
last topic...
0
 

Author Comment

by:givatada
Comment Utility
Richie_Simonetti :
Your solution doesnt help me!

Is it possible to use the "Headers" param when i use
"Webbrowser1.navigate strUrl,,"Pwd" ? or somthing like that?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
I don't think so. My example is usefull to use instead of sendkeys stuff...
just a question: why do you use a webbrowser to display word's doc?
0
 

Author Comment

by:givatada
Comment Utility
Richie_Simonetti :
I use wb` because i need to display the doc on my form,
and i could not open word and set my form as its parent.
please show me how...

2. if i use richtext, the doc`s style is ruin.

anyway, it works very good with wb` except this pwd issue.

Guy.

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
"...and i could not open word and set my form as its parent.
please show me how...
"
cannot you by design or don't you know how?

If last:

'You need to go to project, references menu and add microsoft word object library to your project:


Option Explicit
' general declarations section
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long)
As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal
lpWindowName As String) As Long

Dim wdApp As Word.application
dim wdoc as word.document
Private Sub Form_Load()
Set wdApp = New Word.application
wdApp.Visible = True
'wdApp.Documents.Add
'or
set wdoc = wdApp.Documents.Open "c:\mydoc.doc"
wdoc.unprotect "password"
Dim ret As Long
ret = FindWindow("Opusapp", vbNullString)
SetParent ret, Me.hWnd
End Sub

Also
0
 

Author Comment

by:givatada
Comment Utility
Richie_Simonetti:
This is very good.
but:I must remove all menus from the doc.
all the functionality that the user can have, must be from my forms menu!

IF it can be done(removing the menu), i will accept your nice solution.

Guy
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Yes, you can.
I haven't the code right now but the idea is enumerate all commandbars visible, store their values in some place and simply set their visible property to false.
something like this (pseudo code!):
Dim arrCBars() As String
Sub test()
Dim cb As word.CommandBar

Dim idx As Integer
For Each cb In wdApp.CommandBars
    If cb.Visible = True Then
       ReDim Preserve arrCBars(idx)
       arrCBars(idx) = cb.Name
       idx = idx + 1
       cb.Visible = False
    End If
Next
End Sub
Don't forget to restore them when you are finished since it will affect Word the next time your user open it.
Hope it helps
0
 

Author Comment

by:givatada
Comment Utility
Richie_Simonetti :

I tryed this -
For i = 1 To wdApp.CommandBars.Count
   wdApp.CommandBars(i).Visible = False
Next i

The MenuBar did not vanished.

"---Dim cb As word.CommandBar---"
there is no "word.CommandBar" type.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Holly smoke!
Commandbar object is part of Office library not word library. You need to add that reference to your project. Sorry for the inconvenience.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:givatada
Comment Utility
well, it works, but in fatal exit, the normal.dot remains without the menubar. I can see that this solution may be problematic. if its possible to use the existing webBrowser control in my app, plus passing the pwd when opening files, I prefer.
may be I should unprotect the doc before opening it, and reprotect it when done. what do you think?
0
 

Author Comment

by:givatada
Comment Utility
It must be fast performance
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
This is what i use:

Sub HideBars()
' hides all commandbars
' You need a reference to Microsoft office library
Dim cb As CommandBar
Dim idx As Integer

For Each cb In wdApp.CommandBars
 With cb
   If cb.Visible = True Then
      ReDim Preserve arrCBars(idx)
      arrCBars(idx) = cb.Name
      idx = idx + 1
      If cb.Name = "Menu Bar" Then
        .Enabled = False
      Else
        cb.Visible = False
    End If
   End If
 End With
Next
End Sub


Private Sub Form_Unload(Cancel As Integer)
Dim idx As Integer

For idx = 0 To UBound(arrCBars)
    If arrCBars(idx) = "Menu Bar" Then
        wdApp.CommandBars(arrCBars(idx)).Enabled = True
      Else
       wdApp.CommandBars(arrCBars(idx)).Visible = True
    End If
Next idx
End Sub
0
 

Author Comment

by:givatada
Comment Utility
Ok.I can see your approach.
please tell me what do you think about the UnProtecting
and Protecting the docs as nececcery, before i will accept this.
I will now try to use your code in my app.
the added reference is not so good because i will have to include it in the P&D.
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 200 total points
Comment Utility
Protect and unprotect would be fine.
Regarding reference stuff, you could do this:
First, add rference and write the code. When you have finished doing it and debuging, change all strong typed variables for word object to a generic Object type.
After that, use CreateObject function instead of New stuff:
example:

Dim wdApp As object

set wdApp = createObject("Word.application")

and so on.
Hope i was clear enougth. If not, let me know.
Cheers
0
 

Author Comment

by:givatada
Comment Utility
Richie_Simonetti :
This is wrong because it will include the reference anyway!
set wdApp = createObject("Word.application")

Anyway, I think you are a good expert, and I thank you for all your effort.

Guy
0
 

Author Comment

by:givatada
Comment Utility
Richie_Simonetti :
This is wrong because it will include the reference anyway!
set wdApp = createObject("Word.application")

Anyway, I think you are a good expert, and I thank you for all your effort.

Guy
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Not at all!, You need to clear reference of Word library in your project but code will fails if there is no word installed in target machine anyway. You need to manage 429 error to handle that.
Thanks for "A" grade!
If you need more help, here i am.
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Richie, missed this one......but this is a browser and word on one form just curious

:O)Bruintje
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Hi, the program not uses wb anymore (i believe).
It could be use, as you already know, to display not only word but office documents. The problem here is the doc was protected.
Whenever i can, i try to avoid overhead and waste resources if there is another "cheap" option.
The SetParent stuff works like a charm.
thanks to drop some words here... cheers
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now