[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using webBrowser to display word docs:

Posted on 2002-03-17
20
Medium Priority
?
159 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
ID: 6874767
wait...
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6891847
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
ID: 6903557
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6904529
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
ID: 6905784
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
ID: 6906367
"...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
ID: 6906837
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
ID: 6908280
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
ID: 6908687
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
ID: 6909136
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
 

Author Comment

by:givatada
ID: 6909274
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
ID: 6909277
It must be fast performance
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6909644
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
ID: 6909995
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 800 total points
ID: 6910655
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
ID: 6913274
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
ID: 6913280
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
ID: 6913668
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
ID: 6921265
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
ID: 6921412
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

834 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