Solved

Microsoft Word Margin vb script

Posted on 2011-03-07
2
1,697 Views
Last Modified: 2012-05-11
When running the script below to automate adjusting margins
to word files in a specific folder I receive the following error:

script: "c:\test.vbs"
Line: 22
Char: 13
Error: Type mismatch: 'CentimetersToPoints'
Code: 800A000D
Source: Microsoft VBScript runtime error

This is the script:

Dim strFolder

Dim doc 'As Word.Document
Dim fso 'As FileSystemObject
Dim fld 'As Folder
Dim fl 'As File
Dim p 'As Integer
Dim wdApp 'As Word.Application

strFolder = "C:\MyFolder"

Set fso = CreateObject("Scripting.FileSystemObject")
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True

Set fld = fso.GetFolder(strFolder)
For Each fl In fld.Files
    p = InStr(fl.Name, ".")
    Select Case Mid(fl.Name, p)
        Case ".doc", ".docx", ".docm"
            Set doc = wdApp.Documents.Open(fl.Path)
            doc.PageSetup.LeftMargin = CentimetersToPoints(1)
            doc.PageSetup.RightMargin = CentimetersToPoints(1)
            doc.PageSetup.TopMargin = CentimetersToPoints(1.5)
            doc.PageSetup.BottomMargin = CentimetersToPoints(1.5)
            doc.Close -1 'wdSaveChanges
     End Select
wdApp.Quit
Next

Any help would be appreciated.

Thank you.
0
Comment
Question by:cbones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
pteranodon72 earned 500 total points
ID: 35060531
CentimetersToPoints is a function of the Word application. Try:

doc.PageSetup.LeftMargin = wdApp.CentimetersToPoints(1)
doc.PageSetup.RightMargin = wdApp.CentimetersToPoints(1)
doc.PageSetup.TopMargin = wdApp.CentimetersToPoints(1.5)
doc.PageSetup.BottomMargin = wdApp.CentimetersToPoints(1.5)

HTH,
pT72
0
 

Author Comment

by:cbones
ID: 35061981
That worked perfect.  Thank you very much for your help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question