• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Using webBrowser to display word docs:

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
givatada
Asked:
givatada
  • 10
  • 9
1 Solution
 
Richie_SimonettiIT OperationsCommented:
wait...
0
 
Richie_SimonettiIT OperationsCommented:
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
 
givatadaAuthor Commented:
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Richie_SimonettiIT OperationsCommented:
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
 
givatadaAuthor Commented:
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
 
Richie_SimonettiIT OperationsCommented:
"...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
 
givatadaAuthor Commented:
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
 
Richie_SimonettiIT OperationsCommented:
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
 
givatadaAuthor Commented:
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
 
Richie_SimonettiIT OperationsCommented:
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
 
givatadaAuthor Commented:
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
 
givatadaAuthor Commented:
It must be fast performance
0
 
Richie_SimonettiIT OperationsCommented:
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
 
givatadaAuthor Commented:
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
 
Richie_SimonettiIT OperationsCommented:
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
 
givatadaAuthor Commented:
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
 
givatadaAuthor Commented:
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
 
Richie_SimonettiIT OperationsCommented:
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
 
bruintjeCommented:
Richie, missed this one......but this is a browser and word on one form just curious

:O)Bruintje
0
 
Richie_SimonettiIT OperationsCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now