Solved

Microsoft Word Margin vb script

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
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.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now