Microsoft KB Archive/115782

{|
 * width="100%"|

HOWTO: Have a VB Program Change a Word Document's Page Layout

 * }

Q115782

-

The information in this article applies to:


 * Microsoft Visual Basic Standard and Professional Editions for Windows, version 3.0
 * Microsoft Word for Windows, version 6.0

-

SUMMARY
The stretch setting of the SizeMode property re-sizes an OLE server's image to best fit the dimensions of the MSOLE2.VBX control. OLE servers, such as Word for Windows, are responsible for the display of the image inside an OLE container. OLE servers will create a display based on a unit defined by the server. For example, the display of a Word for Windows version 6.0 document is based on the Page Layout dimensions of the document and the amount of vertical text being displayed. This article gives two techniques you can use to alter the appearance of a Word object in the OLE control.

MORE INFORMATION
The ChangePageSize Sub procedure defined in the following example is a generic routine that accepts three parameters (the OLE control, a string for page height, and a string for page width). The ChangePageSize Sub procedure redefines the page height and width based on the parameters passed to it. Both strings (page height and page width) must include a unit of measure. The following example uses inches as the unit of measure. The ChangePageSize Sub procedure expects the second and third parameters to represent the page height and page width.

Steps to Create Example Program for Changing a Page Size

 * 1) Start a new project in Visual Basic. Form1 is created by default.
 * 2) Add a command button (Command1) to Form1.
 * 3) Create a control array of three Command1 buttons. From the Edit menu, choose Copy. Then from the Edit menu, choose Paste. You will be asked if you want to create a control array of Command1 buttons. Choose the Yes button. Continue this process for a total of three Command1 buttons. Change the caption on the first button to 100%, the caption on the second button to 75%, and the caption on the third button to 50%.
 * 4) Add the following code to Command1_Click (Index As Integer) event procedure:
 * 5) Add the following Sub procedure to the General Declarations section of Form1:
 * 6) Add an MSOLE2.VBX control to Form1 and select the Create from File option. Then choose the Browse button and find the desired document to load. Next select the Display as Icon option, and choose the OK button.
 * 7) Run the sample. Click the 50% button to see the document displayed at 50% of the page size. Then click the 75% button to see the document displayed at 75% of the page size. Finally, click the 100% button to see the document displayed at 100% of the page size.

Steps to add to the Example Program for Changing the Margin Size
The ChangeMargins Sub procedure listed in the following example is a generic routine that excepts five parameters (the OLE control and four string type parameters for the four margin settings).

The ChangeMargins Sub procedure redefines the page margins (top, bottom, left, and right) based on the parameters passed to it. All four of the margin strings must include a unit of measure, which for the following example is inches. In the ChangeMargins Sub procedure, the second, third, fourth and fifth parameters set the margins. The second parameter represents the value for the top margin, the third represents the value for the bottom margin, the fourth represents the value for the left margin, and the fifth represents the value for the right margin.


 * 1) Add a command button (Command2) to Form1.
 * 2) Create a control array of four Command2 buttons. From the Edit menu, choose Copy. Then from the edit menu, choose Paste. When asked if you want to create a control array of Command1 buttons, choose the Yes button. Continue this process for a total of four Command2 buttons. Change the first button's caption to Default, the second button's caption to No Margins, the third button's caption to 1/2 Inch, and the fourth button's caption to 1 Inch.
 * 3) Add the following code to the Command2_Click (Index As Integer) event procedure:
 * 4) Add the following Sub procedure to the General Declarations section of Form1:
 * 5) Press the F5 key to run the application. Click the 1 Inch button to see the document displayed with a one-inch margin. Click the 1/2 Inch button to see the document displayed with a one-half-inch margin. Click the No Margins button to see the document displayed with no margin. Click the Default button to use the Microsoft Word default margin setting.

Additional query words: OLE Automation OA OLE2

Keywords : kbmacro kbVBp300 kbDSupport IAPOLE

Issue type : kbhowto

Technology :