Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VIEW doc word in form but at 70% not 100% 1

Status
Not open for further replies.
You have set the Zoom property, path: Document>Window>View>Zoom. VB code here.

combo
 
>need to show in form

How are you currently showing "in form"?
 
So, let's break this down. Your primary question is:

How do I show a Word document on a VB6 form?

Is that correct?
 
Drop an OLE container control onto the form. Click 'Canc el' in the resulting Insert Object dialog.

Then in code you can open any word doc you like as follows:

OLE1.CreateEmbed "pathtomyfile", "Word.Document"

And that's pretty much it.

You can then access and automate the word document via OLE1.Object

(one challenge with this is your next requirement - zooming out - as the Zoom method suggested by combo doesn't work with the window shown by the OLE control)
 
>Zoom method ... doesn't work

I think I may have a solution to the Zoom issue. Quick question before I put the effort in to an example - are you just using wanting to VIEW the Word document, not interact with it to edit etc?
 
not interact with it to edit etc!
Only show It, lock It for edit.
 
Ok .. in that case I've got a basic Proof of Concept working. just need a tiny tidy up before posting.
 
OK, enough teasing ...

You will need a form with:
a) Picturebox which will host our zoomed view control (which is also a picturebox). Call it OLEProxieHost. Give itr a different colour background (i use the Application Workspace colour, )
b) Another picturebox, placed inside the first picturebox; call it OLEProxieView
c) horizontal scrollbar
d) A label
e) an OLE control, hidden (either visibility set to none, or outside the form borders (feel free to leave this with default name, OLE1)

Note I only use OLEProxieHost as a cheap way to restrict the zoom limits of the OLEProxieView. It is not a criotical part of the idea

And then copy and paste this code into your form module:

Code:
[COLOR=blue]Option Explicit

Private myscale As Single

Private Sub Form_Load()
    OLE1.SizeMode = vbOLESizeAutoSize [COLOR=green]' ensures we have an enhanced metafile picture in the OLE container[/color]
    OLE1.CreateEmbed "f:\testing.docx", "Word.application" [COLOR=green]' Here is where we load our word doc[/color]
    OLEZoom = 75 [COLOR=green]' initial zoom %[/color]
End Sub

Private Sub OLEZoom_Change()
    Label1.Caption = Format(OLEZoom / 100, "0%")
    DrawOLEView
End Sub

Public Sub DrawOLEView()
    myscale = OLEZoom / 100
    OLEProxieView.Width = OLE1.Picture.Width * ScaleX(1, 8, 1) * myscale
    OLEProxieView.Height = OLE1.Picture.Height * ScaleY(1, 8, 1) * myscale
    OLEProxieView.AutoRedraw = True
    OLEProxieView.Cls
    [COLOR=green]' This is the line that does all the hard work[/color]
    OLE1.Picture.Render OLEProxieView.hDC, 0, 0, OLE1.Picture.Width * ScaleX(1, 8, 3) * myscale, OLE1.Picture.Height * ScaleY(1, 8, 3) * myscale, 0, OLE1.Picture.Height, OLE1.Picture.Width, -OLE1.Picture.Height, 0&
    OLEProxieView.AutoRedraw = False
    OLEProxieView.Refresh
End Sub[/color]

Altrernatively, just try this zipped vb6 project



 
 https://files.engineering.com/getfile.aspx?folder=a53ccc9e-39f8-49b5-842a-5f6b4a36f49e&file=WordZoom.zip
Have you considered issuing a purple star 9'great Popst') to any of your recent threads, such as

thread222-1816156
thread222-1816151
thread222-1816138
thread222-1814392
thread222-1813872

This not only encourages those who have helped you to help you again in the future, but also makes it easier for future visitors with similar questions to identify threads that might help them

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top