Converting Visual Basic inside Word Document to VBScript

M

Mark Holland

Hello,

I am trying to put MS Word COM Objects in to a VBScript - I am struggling
with a bit of translation.

Basically I want to alter a Heading style.....

I use Word Macro to get me the code, which is....

objSelection.Style = ActiveDocument.Styles("Heading 1")
With ActiveDocument.Styles("Heading 1").ParagraphFormat
.LeftIndent = CentimetersToPoints(1.27)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 12
.SpaceBeforeAuto = False
.SpaceAfter = 3
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = True
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints(-0.63)
.OutlineLevel = wdOutlineLevel1
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With

How do I put that in to VBScript??

I understand I have to create the object and create a new document (as below)

set objword = CreateObject("Word.Application")
objword.visible = True
set objDoc = objword.Documents.Add()
set objSelection = objWord.Selection

What else do I need to do??

Many Thanks in advane

Mark Holland
 
S

Steve Yandl

Where you've used Word constants, you need to declare them at the start of
your vbs file. For example, you would want to have the line,
Const wdLineSpaceSingle = 0
Do a search for each of the constants in your VBE window to find the correct
values.

Also, where you use a function like "CentimetersToPoints", you want to
change to something like,
objWord.Application.CentimetersToPoints(1.27)

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

set hanging indent for second TOC 1
TOC Help 0
TOC Problem 0
Table of Content 1
TOC problem 0
TOC Question 3
A macro to increase line spacing 1
Report formatting - Bulleted lists 4

Top