Dave A. wrote:
> I want to convert text files to word and set the page layout every
> mourning.
> It all works except for page formatting. Tried using macro code, but
> not the same from vba to vbscrpt. I copied this from a word macro and
> copied in vbscript code, but it won't work.
>
> With ActiveDocument.PageSetup
> .Orientation = wdOrientLandscape
> .TopMargin = InchesToPoints(0.92)
> .BottomMargin = InchesToPoints(0.92)
> .LeftMargin = InchesToPoints(0.7)
> .RightMargin = InchesToPoints(0.7)
> .PageWidth = InchesToPoints(11)
> .PageHeight = InchesToPoints(8.5)
> End With
>
> I can't set the inches or the orientation.
Assuming that somewhere you do...
Set oWordApplication = CreateObject("Word.Application")
and define
Const wdOrientLandscape = 1
then...
With oWordApplication.ActiveDocument.PageSetup
.Orientation = wdOrientLandscape
.TopMargin = oWordApplication.InchesToPoints(0.92)
.BottomMargin = oWordApplication.InchesToPoints(0.92)
.LeftMargin = oWordApplication.InchesToPoints(0.7)
.RightMargin = oWordApplication.InchesToPoints(0.7)
.PageWidth = oWordApplication.InchesToPoints(11)
.PageHeight = oWordApplication.InchesToPoints(8.5)
End With
> Also is there a place to find all methods/objects for controlling "MS
> Word" from vbScript?
>
Your best source is the Office VBA documentation...
Documentation for Office object models is supplied with every copy of
Office. Start the Office application you're interested in (Word in tnbis
case). On the menu bar, select Help/Contents and Index. In the contents,
select Microsoft Visual Basic Reference/Visual Basic Reference. This will
bring up the VBA help file.
When you read the help on the various objects, properties, methods, etc. you
have to keep in mind that it's written in the context of VBA hosted by a
specific VBA-enabled application, not VBScript. VBA is hosted "from the
inside" by the specific application. As the host, it automatically provides
things to the VBA code that aren't automatic when you automate an
application's object model "from the outside" using VBScript hosted by WSH.
The key items to remember:
--- No objects are automatically exposed to VBScript. You generally use an
explicit CreateObject to get an instance of an object to use as the "root",
usually the ".Application" object.
---In VBA that Application object and it's immediate interface members
(properties/methods) are automatically exposed. In VBScript you refer to the
Application object and it's properties/methods through the object variable
reference returned by the CreateObject.
---Named constants specific to the application aren't exposed. You can
either look them up and code them locally in the VBScript code as Const
variables, or you can use the .wsf file format and a <reference> element to
automatically expose them.
---VBA supports named argument syntax (e.g., ArgName:="argvalue") in method
calls. In WSH hosted VBScript, you have to code all arguments as positional
arguments since named argument syntax is not supported.
Once you understand the "VBA from the inside" vs "VBScript from the outside"
issues and the fundamental differences between VBA and VBScript as separate
but similar languages, you should be able to mentally "port" VBA and even
full VB examples to VBScript.
--
Michael Harris
Microsoft.MVP.Scripting
Sammamish WA US
|