Solved

Microsoft Word Margin vb script

Posted on 2011-03-07
2
1,658 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
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

777 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