Microsoft Word Margin vb script

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

Any help would be appreciated.

Thank you.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

pteranodon72Connect With a Mentor Commented:
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)

cbonesAuthor Commented:
That worked perfect.  Thank you very much for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.