Article View: adobe.scripting.indesign
Article #14860[VB] Find/Change example
From: Olav_Kvern
Date: Wed, 14 Jan 2004 20:41
Date: Wed, 14 Jan 2004 20:41
42 lines
2997 bytes
2997 bytes
Gang--
Someone on the InDesign mailing list just asked about finding/changing U.S. state abbreviations, so I wrote them an example script. Here it is:
Rem FindChangeStates.vbs
Rem An InDesign CS VBScript
Rem Finds two-letter state abbreviations and applies a character style to them.
Set myInDesign = CreateObject("InDesign.Application.CS")
myFindStateArray = Array("AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY")
myChangeStateArray = Array("al", "ak", "as", "az", "ar", "ca", "co", "ct", "de", "dc", "fm", "fl", "ga", "gu", "hi", "id", "il", "in", "ia", "ks", "ky", "la", "me", "mh", "md", "ma", "mi", "mn", "ms", "mo", "mt", "ne", "nv", "nh", "nj", "nm", "ny", "nc", "nd", "mp", "oh", "ok", "or", "pw", "pa", "pr", "ri", "sc", "sd", "tn", "tx", "ut", "vt", "vi", "va", "wa", "wv", "wi", "wy")
If myInDesign.Documents.Count > 0 Then
If myInDesign.ActiveDocument.Stories.Count > 0 Then
Rem Clear the current find/change settings
myInDesign.FindPreferences = idNothingEnum.idNothing
myInDesign.ChangePreferences = idNothingEnum.idNothing
Err.Clear
On Error Resume Next
Set myCharacterStyle = myInDesign.ActiveDocument.CharacterStyles.Item("state")
If Err.Number <> 0 Then
Rem Character style did not exist, so create it.
Set myCharacterStyle = myInDesign.ActiveDocument.CharacterStyles.Add
myCharacterStyle.Name = "state"
myCharacterStyle.Capitalization = idCapitalization.idSmallCaps
Err.Clear
End If
On Error GoTo 0
myInDesign.ChangePreferences.AppliedCharacterStyle = myCharacterStyle
For myCounter = 0 To UBound(myFindStateArray)
Set myFoundItems = myInDesign.ActiveDocument.Search(myFindStateArray(myCounter), True, True, myChangeStateArray(myCounter))
Next
Else
MsgBox "The active document does not contain any text."
End If
Else
MsgBox "Please open a document, select an object, and try again."
End If
Thanks,
Ole
Technical Details
Message-ID:
<2ccf5e92.-1@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webxShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,a2817e7d11c28539,start X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2004-01-14 13:08:06 PST From: Olav_Kvern@adobeforums.com Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.scripting.indesign Subject: [VB] Find/Change example Message-ID: <2ccf5e92.-1@webx.la2eafNXanI> Date: Wed, 14 Jan 2004 12:41:30 -0800 Lines: 56 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit