freg
asked on
Embedded Word Document with VB6
Hi,
I would like to know how i can embed an MSWord Document object in a form (i.e. frame control), without using Word.Application (only Word.Document). So far i used the entire Word interface in my forms (2), but it seems to be unstable, so i'dd rather use only Document object, and control it myself.
Thanks,
Freg
I would like to know how i can embed an MSWord Document object in a form (i.e. frame control), without using Word.Application (only Word.Document). So far i used the entire Word interface in my forms (2), but it seems to be unstable, so i'dd rather use only Document object, and control it myself.
Thanks,
Freg
Or just use webbrowser control to navigate to desired document..
ASKER
Hi Richie,
so far :
ret = FindWindow("Opusapp", vbNullString)
SetParent ret, Frame2.hwnd
to embed the entire Word.Application window. What for the brand new document object ?
so far :
ret = FindWindow("Opusapp", vbNullString)
SetParent ret, Frame2.hwnd
to embed the entire Word.Application window. What for the brand new document object ?
it is a little more api involved since you have to loop child windows of opusapp
example:
'in a form
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Me.AutoRedraw = True
EnumChildWindows FindWindow("Opusapp", vbNullString)
, AddressOf EnumChildProc, ByVal 0&
End Sub
'in a module
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sSave As String
'Get the windowtext length
sSave = Space$(GetWindowTextLength (hwnd) + 1)
'get the window text
GetWindowText hwnd, sSave, Len(sSave)
'remove the last Chr$(0)
sSave = Left$(sSave, Len(sSave) - 1)
If sSave <> "" Then Form1.Print sSave
'continue enumeration
EnumChildProc = 1
End Function
But i think webbrowser control would be better for your work, isn't it?
example:
'in a form
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Me.AutoRedraw = True
EnumChildWindows FindWindow("Opusapp", vbNullString)
, AddressOf EnumChildProc, ByVal 0&
End Sub
'in a module
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sSave As String
'Get the windowtext length
sSave = Space$(GetWindowTextLength
'get the window text
GetWindowText hwnd, sSave, Len(sSave)
'remove the last Chr$(0)
sSave = Left$(sSave, Len(sSave) - 1)
If sSave <> "" Then Form1.Print sSave
'continue enumeration
EnumChildProc = 1
End Function
But i think webbrowser control would be better for your work, isn't it?
_WwC is the classname for document window.
ASKER
Concerning WebBrowser, i must be able to type character and edit the .doc. Does that control permit edition ?
I think so but you have to manage the save event by yourself since webbrowser will not save the doc automatically.
ASKER
How can i user WebBrowser control ? Is it included with visual studio 6 ?
Yes, do a right click in Toolbox window, choose Components...
Locate Microsoft nternet control (NOT Internet transfer control)
Do a click in the check box at left side an do a click in OK button
From here you could add to your form like any other control.
Locate Microsoft nternet control (NOT Internet transfer control)
Do a click in the check box at left side an do a click in OK button
From here you could add to your form like any other control.
'When you have added the control do the following:
dim withevents wdoc as word.document
'where you want to open word document use this code:
webbrowser1.navigate "path_to document goes here"
'At Documentcomplete event of webbrowser
if (pDisp is webbrowser.object) then
set wdoc = webbrowser1.document
end if
'done, automate wdoc as usually.
dim withevents wdoc as word.document
'where you want to open word document use this code:
webbrowser1.navigate "path_to document goes here"
'At Documentcomplete event of webbrowser
if (pDisp is webbrowser.object) then
set wdoc = webbrowser1.document
end if
'done, automate wdoc as usually.
ASKER
That seems fine. But tell me, why is it better to use WebBrowser control instead of embed Word.Document objet and use it directly ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok then ! Thanks a lot Ritchie !
Glad to help you... (again ;)
Thanks for "A" grade.
Thanks for "A" grade.
ASKER
lol i think it was you last time isn't it (concerning embedded word again) ?
If you need more help on this, don't post other Q and spend your points, we could continue here.
(i know, i know, i am a nice person... :))
(i know, i know, i am a nice person... :))
ASKER
Great ! you ARE very nice !
ASKER
Ritchie,
One little thing : After i modified my document (.doc) and finished to work on it, i do wdoc.SaveAs, and then i change it by WebBrowser1.Navigate "anotherdoc.doc", so the WebBrowser control bother me with a messagebox asking if i want to save the changes... any idea to withdraw that annoying function ?
One little thing : After i modified my document (.doc) and finished to work on it, i do wdoc.SaveAs, and then i change it by WebBrowser1.Navigate "anotherdoc.doc", so the WebBrowser control bother me with a messagebox asking if i want to save the changes... any idea to withdraw that annoying function ?
humm, it appears that:
1) You are saving your cached document
2) You are saving document at server side.
We could try two things:
1) before navigate to anotherdoc.doc, do:
wdoc.saved = true
2)
wdoc.Application.DisplayAl erts =0
1) You are saving your cached document
2) You are saving document at server side.
We could try two things:
1) before navigate to anotherdoc.doc, do:
wdoc.saved = true
2)
wdoc.Application.DisplayAl
ASKER
Well it seems that it doesn't work. But i bypass the problem as it :
' Make a copy of the source template file :
FileCopy "D:\PVTemplate.dot", "D:\Temp.dot"
' Open the temp file :
WebBrowser1.Navigate "D:\Temp.dot"
' And then save as the real name :
wdoc.SaveAs "D:\MyDoc.doc"
' Save again to deactivate the message
' But here, the copy is made on Temp.dot instead of MyDoc.doc (bizarre)
wdoc.Save
WebBrowser1.Navigate "D:\Another.doc"
' Kill the temporary file
Kill "D:\Temp.dot"
Ritchie, if you get any more information about that problem, let me know ! ;-)
' Make a copy of the source template file :
FileCopy "D:\PVTemplate.dot", "D:\Temp.dot"
' Open the temp file :
WebBrowser1.Navigate "D:\Temp.dot"
' And then save as the real name :
wdoc.SaveAs "D:\MyDoc.doc"
' Save again to deactivate the message
' But here, the copy is made on Temp.dot instead of MyDoc.doc (bizarre)
wdoc.Save
WebBrowser1.Navigate "D:\Another.doc"
' Kill the temporary file
Kill "D:\Temp.dot"
Ritchie, if you get any more information about that problem, let me know ! ;-)
Not at this moment. I have to do test to see the problem.
ASKER
Hi again Ritchie !
One more problem with wdoc object : while i edit the wdoc in the webbrowser object and everything is fine, but as soon i start MSWord aside (with a new document for example), it becomes impossible for me to edit the wdoc anymore (in webbrowser). As if MSWord application took the entire control of my wdoc object.
Any idea ??
One more problem with wdoc object : while i edit the wdoc in the webbrowser object and everything is fine, but as soon i start MSWord aside (with a new document for example), it becomes impossible for me to edit the wdoc anymore (in webbrowser). As if MSWord application took the entire control of my wdoc object.
Any idea ??
ASKER
...and if there's no concrete solution, maybe could we "block" the execution of MSWord application. Since i can detect (with findwindow) it and notify the user to close MSWord, that remains ok. But if a user start MSWord app AFTER the execution of my program, all the edition feature is compromised (very bad).
(by the way, if you get any solution about that i'll be glad to allow you some more points)
;-)
(by the way, if you get any solution about that i'll be glad to allow you some more points)
;-)
Points are not the problem, iwhat i need is time. I am very busy at this moment.
ASKER
Ok then. I'll wait...
Thanks !
Thanks !
Are you using Office XP?
ASKER
It's Office 2000
I cannot reproduce your error.
1) i Navigated to desired document
2) edit it, saved
3)modified again
4)open Word app
5)save it
6) Modify again, saved
7)Modify again, not saved
8)Close word
9) close browser, ask for save, saved
1) i Navigated to desired document
2) edit it, saved
3)modified again
4)open Word app
5)save it
6) Modify again, saved
7)Modify again, not saved
8)Close word
9) close browser, ask for save, saved
hihi,
can i prevent the popup of asking to download the word file after calling this?
WebBrowser1.Navigate "D:\Another.doc"
can i prevent the popup of asking to download the word file after calling this?
WebBrowser1.Navigate "D:\Another.doc"
ASKER
hum... bizarre, i don't know. Maybe Richie got an answer...?
That should due to you have not Word installed.
not really...
i have installed MSWord in my machines already.
but as now i am using the Microsoft Internet Control. where it open the word document. It will prompt a message to ask to open or save...
you can try out this by opening an Internet Explorer and then type the location of your word file...(eg. D:\Another.doc)
can i skip this popup when i use the control?
i have installed MSWord in my machines already.
but as now i am using the Microsoft Internet Control. where it open the word document. It will prompt a message to ask to open or save...
you can try out this by opening an Internet Explorer and then type the location of your word file...(eg. D:\Another.doc)
can i skip this popup when i use the control?
I do, but i load word document inside internet explorer. Maybe, there is an issue with security settings on IE.
so it means it is impossible to use the microsoft internet control in vb6 to view word document which bypass the file download dialog box to ask for open or save?
or any other method i can use in order to view word document(actually i only wanna view without editing) by using vb6 except OLE and MS internet control?
or any other method i can use in order to view word document(actually i only wanna view without editing) by using vb6 except OLE and MS internet control?
You could try the first approach (Setparent API stuff), see at the beginning of this Q.
could me give me some sample code on it?
why set parent can do it? it can by pass the file download window?
what is opusapp?
why set parent can do it? it can by pass the file download window?
what is opusapp?
ASKER
It embed a word app in a VB6 control. Try the code above, as ritchie suggested.
Actually i would like to show a word document in the form of vb6 so that user can view the document. Editing is not neccessary.
findWindow and setparent can make the word document embed to the form?
how?
findWindow and setparent can make the word document embed to the form?
how?
i can embed the whole word application in the frame now..
but can't embed the word document only...
even if i use _WwC
dim a as long
set a = FindWindow("_WwC", "ABC.doc")
how can i embed word document only?
but can't embed the word document only...
even if i use _WwC
dim a as long
set a = FindWindow("_WwC", "ABC.doc")
how can i embed word document only?
ASKER
Try to, instead using a Word.Application object, use a Word.Document object.
No. You are doing wrong way. Use FindWindow to locate main word app but use enumchildwindow to locate word document window.
Thanks for your suggestions, and i can work it out now..
however...can i resize the word document so that the word document size will follow the size changes of the form?
thanks a lot.
however...can i resize the word document so that the word document size will follow the size changes of the form?
thanks a lot.
i have solved the problem already ..
thanks a lot.
thanks a lot.
Richie_Simonetti,
I embedded word into my form, but how can I make it close the form when I close word
also
How can u make work maximize to the form size on opening, I tried wdvbmaximized and nothing happens
I embedded word into my form, but how can I make it close the form when I close word
also
How can u make work maximize to the form size on opening, I tried wdvbmaximized and nothing happens
peanut1010
i don't know what wdvbmaximized means but if you want to maximize the word document to fill your form and to manage close event of word to do the same thing with your form, you need an object reference variable pointing to that word document, have you one already declared and setted?
i don't know what wdvbmaximized means but if you want to maximize the word document to fill your form and to manage close event of word to do the same thing with your form, you need an object reference variable pointing to that word document, have you one already declared and setted?
I figured out what to do with that thanks.
But lets say the user close Word, is there a way that it could also close the Form that is the parent to it.
MEaning you have
Setparent, ret me.hwnd
with is my form1
now when the user closes word form1 is still open. Can you program that, also I want to remove a menu option, lets say "Print" which is under file is that possible.
If that is too detailed to show please let me know and I will open up a question. I ran into your name and seen that u knew a lot about this.....
But lets say the user close Word, is there a way that it could also close the Form that is the parent to it.
MEaning you have
Setparent, ret me.hwnd
with is my form1
now when the user closes word form1 is still open. Can you program that, also I want to remove a menu option, lets say "Print" which is under file is that possible.
If that is too detailed to show please let me know and I will open up a question. I ran into your name and seen that u knew a lot about this.....
"and seen that u knew a lot about this....."
that's not totally true but thanks.
Have you an object variable pointing to word document?, is it declared withevents?
if so, put this code under it:
unload me
If it is the only form, it should close your app too.
that's not totally true but thanks.
Have you an object variable pointing to word document?, is it declared withevents?
if so, put this code under it:
unload me
If it is the only form, it should close your app too.
this is what I have
Set wdapp = New Word.Application
With wdapp
'wdApp.Documents.Add
'or
Set wddoc = .Documents.Open(sdestinati on, , False)
.WindowState = wdWindowStateNormal
.DisplayAlerts = wdAlertsNone
.Visible = True
End With
Dim ret As Long
ret = FindWindow("Opusapp", vbNullString)
SetParent ret, form1.hwnd
form1.Show
form1.WindowState = vbMaximized
'this bottom line maximizes word on form1
wdapp.WindowState = wdWindowStateMaximize
Set wdapp = New Word.Application
With wdapp
'wdApp.Documents.Add
'or
Set wddoc = .Documents.Open(sdestinati
.WindowState = wdWindowStateNormal
.DisplayAlerts = wdAlertsNone
.Visible = True
End With
Dim ret As Long
ret = FindWindow("Opusapp", vbNullString)
SetParent ret, form1.hwnd
form1.Show
form1.WindowState = vbMaximized
'this bottom line maximizes word on form1
wdapp.WindowState = wdWindowStateMaximize
Hummm.
No.
dim withevents wdapp as word.application
'eventually dim withevents wddoc as word.document
'then, on:
Private Sub wdapp_Quit()
unload me ' or myform
End Sub
No.
dim withevents wdapp as word.application
'eventually dim withevents wddoc as word.document
'then, on:
Private Sub wdapp_Quit()
unload me ' or myform
End Sub
it works though, what is the way you are want me to do it????
how would u eliminate menu buttons????
"it works though, what is the way you are want me to do it????"
Sorry, my english is not so good... what did you mean?
For menu, you could hide the entire menu bar.
Sorry, my english is not so good... what did you mean?
For menu, you could hide the entire menu bar.
Sorry for to be so general is the postings but i haven't VB installed anymore
:(
:(
not the menu certain items in the menu, example = print, save, etc
if u don't have vb what do u use now then. just curoius
if u don't have vb what do u use now then. just curoius
MS Excel to test some of th examples.
At this moment, i am not programming at all, just a little Lotus Notes/LotusScript stuff.
I didn't hide some of the menu items before... i must take a look on how to do it.
At this moment, i am not programming at all, just a little Lotus Notes/LotusScript stuff.
I didn't hide some of the menu items before... i must take a look on how to do it.
you could use setparent api too here.
Just use with hwnd of word document window not word app and hide main word window.