-
Oct 19th, 2005, 05:16 AM
#1
Thread Starter
Lively Member
How to display WORD document in form?
Hi guys...I have a WORD document with text and pictures inside, say for example 5 pages...
Is it possible to display the WORD document in a form if so how do I do that? Would be great if some simple sample code can be provided for me to build on.......
Thanks
-
Oct 19th, 2005, 05:35 AM
#2
Re: How to display WORD document in form?
There are two ways to go here.
You can either open the document directly by opening a session of Word, or you could put an OLE control on your form and link it to a document.
The latter is less flexible.
If you just want to open it, set a reference to the Microsoft Word Object Library, and do something like:
VB Code:
Private Sub Command1_Click()
Dim oWord As Word.Application
Dim oDoc As Word.Document
Set oWord = GetObject(, "Word.Application")
If oWord Is Nothing Then
Set oWord = CreateObject("Word.Application")
End If
oWord.Documents.Open FileName:="d:\worddocs\gone.doc"
oWord.Documents("gone.doc").Activate
Set oDoc = oWord.ActiveDocument
oWord.Visible = True
End Sub
-
Oct 19th, 2005, 06:26 AM
#3
Thread Starter
Lively Member
Re: How to display WORD document in form?
Yes Hack my current program has something liek what you mentioedn which opens and activates WORD seperately.....but what I would liek for this otehr portion is to display the WORD document inside a form.......you know.....like soemtimes when you click on HELP of a program and it pops out with text and pictures inside...
-
Oct 19th, 2005, 06:28 AM
#4
Re: How to display WORD document in form?
Have you tried embedding it as an OLE object?
-
Oct 19th, 2005, 06:36 AM
#5
Thread Starter
Lively Member
Re: How to display WORD document in form?
Erm...I have no idea how to do that.....can u try to guide me along?
Not using ADO right?
-
Oct 19th, 2005, 06:48 AM
#6
Re: How to display WORD document in form?
No, no. On your VB toolbar, you will see a control that has OLE on it.
Place one of those controls on your form.
A window will open up and display a variety of things you can connect to such as a Visio drawing, an Excel Spreadsheet, a Word document, a Powerpoint presentation, just a whole bunch of stuff.
Select the Word document selection, and it should allow you to "connect" to the document of your choice.
I really haven't had a whole lot of actual experience with this control as I normally just use the applications object library and connect to whatever I'm connecting to that way, however, a lot of people prefer this method.
Give it a shot and see if you like it.
-
Oct 19th, 2005, 06:50 AM
#7
Thread Starter
Lively Member
Re: How to display WORD document in form?
Ok thanks...will get back...
-
Oct 19th, 2005, 06:55 AM
#8
Fanatic Member
Re: How to display WORD document in form?
I placed this on PSC a while back [My demo] it shows how you can place the word application within a form like a child.
Hope this helps!!!
Useful Links
.Net
#Develop, GhostDoc, CodeKeep , be.PINVOKE, Good Code Snippet Site
Krypton Toolkit, XPCC / XP Common Controls, QSS Windows Forms Components
VB.COM
VB.Classic Help File, MB Controls, MZTools, ADO Stored Procedure Generator add-in,
-
Oct 19th, 2005, 08:40 AM
#9
Thread Starter
Lively Member
Re: How to display WORD document in form?
Bombdrop, is there a way to do it without creating modules?
I just tried it on OLE...yes the idea is there but the formatting is frustrating...the left part of the OLE box cant seem to be aligned with the left of my WORD document such that part of the text keep getting blocked on the left....and if my WORD os more than 1 page its like the form can only display one page due to the limited maximum size of the form...
Last edited by boroangel; Oct 19th, 2005 at 08:46 AM.
-
Oct 19th, 2005, 08:43 AM
#10
Re: How to display WORD document in form?
Look at using the SetParent API.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Oct 19th, 2005, 09:13 AM
#11
Re: How to display WORD document in form?
Originally Posted by RobDog888
Look at using the SetParent API.
Along with FindWindow.
I elected to put the Word document inside a Frame on my form. If you want to make it a part of the Form itself, please do so. Here is an example.
VB Code:
Option Explicit
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
Private Sub Command1_Click()
Dim lngGetDocHandle As Long
Dim oWord As Word.Application
Dim oDoc As Word.Document
If oWord Is Nothing Then
Set oWord = CreateObject("Word.Application")
End If
oWord.Documents.Open FileName:="d:\worddocs\mydoc.doc"
oWord.Documents("mydoc.doc").Activate
Set oDoc = oWord.ActiveDocument
oWord.Visible = True
lngGetDocHandle = FindWindow(vbNullString, "MyDoc.doc - Microsoft Word")
SetParent lngGetDocHandle, Frame1.hwnd
End Sub
-
Oct 19th, 2005, 09:17 AM
#12
Thread Starter
Lively Member
Re: How to display WORD document in form?
SetParent API? Er..........
-
Oct 19th, 2005, 09:20 AM
#13
Thread Starter
Lively Member
Re: How to display WORD document in form?
Originally Posted by Hack
Along with FindWindow.
I elected to put the Word document inside a Frame on my form. If you want to make it a part of the Form itself, please do so. Here is an example.
VB Code:
Option Explicit
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
Private Sub Command1_Click()
Dim lngGetDocHandle As Long
Dim oWord As Word.Application
Dim oDoc As Word.Document
If oWord Is Nothing Then
Set oWord = CreateObject("Word.Application")
End If
oWord.Documents.Open FileName:="d:\worddocs\mydoc.doc"
oWord.Documents("mydoc.doc").Activate
Set oDoc = oWord.ActiveDocument
oWord.Visible = True
lngGetDocHandle = FindWindow(vbNullString, "MyDoc.doc - Microsoft Word")
SetParent lngGetDocHandle, Frame1.hwnd
End Sub
Hack, for this code, instead of using an OLE.....what control is being used? A Findwindow?
-
Oct 19th, 2005, 09:28 AM
#14
Re: How to display WORD document in form?
FindWindow is an API call and not a control. No OLE but the Word Object Model.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Oct 19th, 2005, 09:38 AM
#15
Re: How to display WORD document in form?
Originally Posted by boroangel
Hack, for this code, instead of using an OLE.....what control is being used? A Findwindow?
You have a variety of options now.
You can just plain open it as my first code example does; you can use the OLE control to embed your document; your can programmatically open it, and place it within a container on your form.
I'd suggest trying all three options to see which one you like the best.
-
Oct 19th, 2005, 09:44 AM
#16
Re: How to display WORD document in form?
The easiest way is to use the WebBrowser control. Instead of pointing it to a URL, specify the path of the Word doc you want to display.
"It's cold gin time again ..."
Check out my website here.
-
Oct 19th, 2005, 09:49 AM
#17
Re: How to display WORD document in form?
Originally Posted by BruceG
The easiest way is to use the WebBrowser control. Instead of pointing it to a URL, specify the path of the Word doc you want to display.
Where did the web come into this?
-
Oct 19th, 2005, 10:05 AM
#18
Re: How to display WORD document in form?
The easiest way is to use the WebBrowser control.
This is a very nice way to view and edit word docs from within a VB form.
-
Oct 19th, 2005, 10:12 AM
#19
Fanatic Member
Re: How to display WORD document in form?
Wouldnt it be easier just to use a rich text box? Then all the formatting can be seen and used.
You could just use something like below like I use in my programs.
VB Code:
With rtbWork
.LoadFile App.Path & "/Files/HowItWorks.rtf"
.SelStart = 0
.SelLength = Len(.Text)
.SelColor = vbYellow
.SelLength = 0
End With
-
Oct 19th, 2005, 10:16 AM
#20
Re: How to display WORD document in form?
Hack -
The WB control can be used not only to navigate to websites, but also to display local Office docs (works for Word, Excel, PowerPoint).
"It's cold gin time again ..."
Check out my website here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|