WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Word

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Change Margin and Fonts in Word DOC

 Keywords: Word Txt Doc Font Margin InchesToPoints SaveAs 

Sample Code:

infile = 'c:\temp\test.txt'
outfile = 'c:\temp\test.doc'


;Get Word Application object handle
objApp = ObjectCreate("Word.Application")
objDocs = objApp.Documents

;Make visisble to end user
objApp.visible = @TRUE

;Open document
objDoc = objDocs.Open( :: FileName = infile)

;Select everything
objSelection = objApp.Selection
objSelection.wholestory


;Set Margin
objSelection.PageSetup.LeftMargin = objApp.InchesToPoints(0.4) ; set these three margins
objSelection.PageSetup.RightMargin = objApp.InchesToPoints(0.4) ; set these three margins
objSelection.PageSetup.TopMargin = objApp.InchesToPoints(1.25) ; set these three margins

;Set Font
objSelection.Font.Size = 9 ; set these three Font specs
objSelection.Font.Bold = @TRUE ; set these three Font specs
objSelection.Font.Name = "courier new" ; set these three Font specs

;SaveAs .DOC
objDoc.SaveAs(::FileName=outfile, FileFormat=0)

;Close document
objDoc.Close

;Free object handles
objDoc = 0
objSelection = 0
objDocs = 0

;Exit Word
objApp.Quit
objApp = 0

Exit



Article ID:   W18149
Filename:   Change Margin and Fonts in Word DOC.txt
File Created: 2008:10:01:07:42:16
Last Updated: 2008:10:01:07:42:16