The 'With' Statement
The With statement enables you to set several properties of an object without typing the name of the object for each property.
This script sets document preferences
Note Adapted from the script on page 177 of the Adobe InDesign 1.5 Scripting Guide..
Without the With Statement |
Using the With Statement |
| Rem Set all document preferences Dim myInDesign As InDesign.Application Dim myDocument As InDesign.Document Dim myDocPreferences As InDesign.DocumentPreference Set myInDesign = CreateObject("InDesign.Application") Set myDocument = myInDesign.ActiveDocument Set myDocPreferences = myDocument.DocumentPreferences myDocPreferences.AllowPageShuffle = False myDocPreferences.PreserveLayoutWhenShuffling = False myDocPreferences.ColumnGuidesColor = idUIMagenta myDocPreferences.ColumnGuidesColor = idUIMagenta myDocPreferences.MarginGuideColor = idUIBlue myDocPreferences.NumberOfPages = 7 myDocPreferences.PageHeight = 658 myDocPreferences.PageWidth = 504 myDocPreferences.PageOrientation = idLandscape myDocPreferences.PagesPerSpread = 2 |
Rem Set all document preferences Dim myInDesign As InDesign.Application Dim myDocument As InDesign.Document Dim myDocPreferences As InDesign.DocumentPreference Set myInDesign = CreateObject("InDesign.Application") Set myDocument = myInDesign.ActiveDocument Set myDocPreferences = myDocument.DocumentPreferences With myDocPreferences .AllowPageShuffle = False .PreserveLayoutWhenShuffling = False .ColumnGuidesColor = idUIMagenta .ColumnGuidesColor = idUIMagenta .MarginGuideColor = idUIBlue .NumberOfPages = 7 .PageHeight = 658 .PageWidth = 504 .PageOrientation = idLandscape .PagesPerSpread = 2 End With |