Skip to main content
Known Participant
December 11, 2008
Question

Getting a CS2 Script to Work in CS4 VB

  • December 11, 2008
  • 3 replies
  • 1298 views
Hi,

The following script works for CS2. I am now trying to run it in CS4 but it
doesn't work. I have put the script in a folder within a folder called
"Version 2.0 Scripts" (inside the preexisting "Scripts Panel" folder).
Nevertheless, it doesn't work. Can anyone help me run this in CS4?

Rem BoxParagraphs.vbs
Rem An InDesign CS2 VBScript
Rem
Rem Converts all paragraphs of a given paragraph style
Rem to single-cell tables.
Set myInDesign = CreateObject("InDesign.Application.CS2")
Set myDocument = myInDesign.Documents.Item(1)
Set myStyle = myDocument.ParagraphStyles.Item("HRBox")
myInDesign.FindPreferences = idNothingEnum.idNothing
myInDesign.ChangePreferences = idNothingEnum.idNothing
myInDesign.FindPreferences.AppliedParagraphStyle = myStyle
Set myFoundItems = myDocument.Search()
myInDesign.FindPreferences = idNothingEnum.idNothing
If myFoundItems.Count <> 0 Then
For myCounter = myFoundItems.Count To 1 Step -1
Set myFoundItem = myFoundItems.Item(myCounter)
Set myStartCharacter = myFoundItem.Characters.Item(1)
Rem Special case for the last paragraph in a story.
Set myEndCharacter = myFoundItem.Characters.Item(-1)
If myEndCharacter.Contents = vbCr Then
Set myEndCharacter = myFoundItem.Characters.Item(-2)
End If
Rem Get the text of the paragraph, excluding the return character.
Set myText = myFoundItem.Texts.ItemByRange(myStartCharacter,
myEndCharacter)
Rem Convert the paragraph to a table.
Set myTable = myText.Item(1).ConvertToTable
Rem Adjust table properties here, if necessary.
Next
End If


Thank you,
Ariel
This topic has been closed for replies.

3 replies

Known Participant
December 11, 2008
Hi Ariel,

It's just a typo. Sorry!

Thanks,

Ole
Known Participant
December 11, 2008
No probs. Thanks again for your help.
Ariel
Jongware
Community Expert
Community Expert
December 11, 2008
>why putting it in a Version 2.0 folder didn't work?

That's easier than you think. CS4 is InDesign v.6, CS3 is v.5, and CS2 -- the original target -- is v.4. I have a Version 4.0 Scripts folder and even a Version 3.0 (for CS scripts) which, AFAIK , work just fine.

I don't think InDesign 2.0 already had scripts :-)
Known Participant
December 11, 2008
Ho hum,

The truth is that for a moment there I also thought it was strange calling CS2 v.2. However, I was simply dutifully doing that which is written:

"...To do this, run the script from a folder in the Scripts panel folder
named Version 5.0 Scripts (for InDesign CS3 scripts) or Version 2.0 Scripts
(for InDesign CS2 scripts), or explicitly..."

(Source: Adobe InDesign CS4 Scripting Guide: VB)
Known Participant
December 11, 2008
Hi Ariel,

Try something like this:

Rem BoxParagraphs.vbs

Rem An InDesign CS4 VBScript
Rem
Rem Converts all paragraphs of a given paragraph style
Rem to single-cell tables.
Set myInDesign = CreateObject("InDesign.Application.CS4")
Set myDocument = myInDesign.Documents.Item(1)
Set myStyle = myDocument.ParagraphStyles.Item("HRBox")
myInDesign.FindTextPreferences = idNothingEnum.idNothing
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
myInDesign.FindTextPreferences.AppliedParagraphStyle = myStyle
Set myFoundItems = myDocument.FindText()
myInDesign.FindTextPreferences = idNothingEnum.idNothing
If myFoundItems.Count <> 0 Then
For myCounter = myFoundItems.Count To 1 Step -1
Set myFoundItem = myFoundItems.Item(myCounter)
Set myStartCharacter = myFoundItem.Characters.Item(1)
Rem Special case for the last paragraph in a story.
Set myEndCharacter = myFoundItem.Characters.Item(-1)
If myEndCharacter.Contents = vbCr Then
Set myEndCharacter = myFoundItem.Characters.Item(-2)
End If
Rem Get the text of the paragraph, excluding the return character.
Set myText = myFoundItem.Texts.ItemByRange(myStartCharacter, myEndCharacter)
Rem Convert the paragraph to a table.
Set myTable = myText.Item(1).ConvertToTable
Rem Adjust table properties here, if necessary.
Next
End If

Thanks,

Ole
Known Participant
December 11, 2008
Thank you very much Ole.

The only difference I can see is the FindPreferences becomes
FindTextPreferences throughout.

I plan to learn up on the new CS4 stuff, but now is not the time as I've got
to finish something here asap.

Just wondering, though, why putting it in a Version 2.0 folder didn't work?

Thanks again,
Ariel
Known Participant
December 11, 2008
Oh, and I see that method is now FindText() rather than Search()