Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

Converting Visual Basic inside Word Document to VBScript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Holland - 17 Oct 2007 11:32 GMT
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
Steve Yandl - 17 Oct 2007 14:44 GMT
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

> Hello,
>
[quoted text clipped - 45 lines]
>
> Mark Holland
Mark Holland - 17 Oct 2007 15:54 GMT
Hi Steve,

Thanks for that! Both comments have been very useful!!

MArk

> 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,
[quoted text clipped - 57 lines]
> >
> > Mark Holland
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.