Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Setting Word PageSetup with vbScript

Reply
Thread Tools Display Modes

Setting Word PageSetup with vbScript

 
 
Dave A.
Guest
Posts: n/a

 
      06-09-2004
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.
When I open converted word doc, orientation still in portrait and margins are .01 in stead of .7 inches.
What can I substitute for function InchesToPoints() and proper orientation setting?
Also is there a place to find all methods/objects for controlling "MS Word" from vbScript?

Thanks,
Dave A.


 
Reply With Quote
 
 
 
 
Michael Harris \(MVP\)
Guest
Posts: n/a

 
      06-09-2004
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

 
Reply With Quote
 
Dave A.
Guest
Posts: n/a

 
      06-09-2004
Thanks for all the help.
Your explaination saved me alot of time and frustration.

Dave A.


"Michael Harris (MVP)" wrote:

> 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
>
>

 
Reply With Quote
 
Leviatano
Guest
Posts: n/a

 
      10-28-2009


"Michael Harris (MVP)" wrote:

> 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
>
>

 
Reply With Quote
 
Leviatano
Guest
Posts: n/a

 
      10-28-2009


"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.
> When I open converted word doc, orientation still in portrait and margins are .01 in stead of .7 inches.
> What can I substitute for function InchesToPoints() and proper orientation setting?
> Also is there a place to find all methods/objects for controlling "MS Word" from vbScript?
>
> Thanks,
> Dave A.
>
>

 
Reply With Quote
 
Leviatano
Guest
Posts: n/a

 
      10-28-2009


"Dave A." wrote:

> Thanks for all the help.
> Your explaination saved me alot of time and frustration.
>
> Dave A.
>
>
> "Michael Harris (MVP)" wrote:
>
> > 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
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting Word 07 as default: problems 98melvillej Windows Vista Installation 7 06-21-2009 08:48 PM
setting a word document as your desktop wallpaper confused Windows Vista Music, Pictures and Video 1 10-06-2007 09:16 PM
Creating Word document of Word 97-2003 file type on the New menu in Vista MikroXP Windows Vista General Discussion 7 03-19-2007 03:59 PM
Can I call a VBscript from another VBscript? Wesley Scripting 4 05-26-2004 06:34 PM
Setting Logon hours with VBScript Cameron Pike Scripting 1 08-01-2003 07:44 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59