🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #19374

Re: Table inconsistency

#19374
From: Olav Kvern
Date: Wed, 08 Jan 2003 20:30
62 lines
3670 bytes
Gunnar--

In general, don't use For Each...Next constructions with InDesign. InDesign's collection objects will only iterate through the first 256 objects in the collection--this was done intentionally to prevent the VB watch window/locals window from crashing.

Next, if you're using VB5 or VB6, you can turn Option Explicit off when you want to process heterogenous collections. (If you're using .NET, you're out of luck, as some moron at Microsoft wanted to impose his or her programming practices on everyone else.) That will do away with the type mismatch error.

Here's an example:



Rem Create an example table and demonstrate cell access methods 
Dim myInDesign As InDesign.Application 
Dim myCell As InDesign.Cell 
Dim myTable As InDesign.Table 
Set myInDesign = CreateObject("InDesign.Application.2.0") 
Set myDocument = myInDesign.Documents.Add 
Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Add 
myTextFrame.GeometricBounds = myGetBounds(myDocument.Pages.Item(1), myDocument) 
myTextFrame.TextContents = "Table 1" & vbCr & "1" & vbTab & "2" & vbTab & "3" & vbCr & "Table 2" & vbCr & "1" & vbTab & "2" & vbTab & "3" & vbCr 
Set myStory = myTextFrame.ParentStory 
Rem Label the story with an unique id 
myStory.Label = "myStoryToFind" 
For myCounter = 2 To 4 Step 2 
    Set myParagraph = myStory.Paragraphs.Item(myCounter) 
    Set myFirstCharacter = myParagraph.Characters.Item(1) 
    Set myLastCharacter = myParagraph.Characters.Item(-2) 
    Set myTable = myStory.Paragraphs.Item(2).Characters.ItemByRange(myFirstCharacter, myLastCharacter).Item(1).Tables.Add 
    If myCounter = 4 Then 
        Rem Give the table a label 
        myTable.Label = "myTableToFind" 
    End If 
Next 
Rem Unlike almost every other object in InDesign, you cannot find a story by its script label using: 
Rem Set myStory = myDocument.Stories.Item("ScriptLabel")--so you have to search for it using iteration. 
For myCounter = 1 To myDocument.Stories.Count 
    If myDocument.Stories.Item(myCounter).Label = "myStoryToFind" Then 
        Set myStory = myDocument.Stories.Item(myCounter) 
        Exit For 
    End If 
Next 
Rem You cannot find a table by its script label using: 
Rem Set myTable = myStory.Tables.Item("ScriptLabel") 
Rem --so you have to search for it using iteration. 
For myCounter = 1 To myStory.Tables.Count 
    If myStory.Tables.Item(myCounter).Label = "myTableToFind" Then 
        Set myTable = myStory.Tables.Item(myCounter) 
        Exit For 
    End If 
Next 
Rem Now that you've found the table you're looking for, find a specific cell. 
Rem You can refer to the cell directly by using its Name property. 
Rem The name of a cell is in the following form: "<Cell Index>:<Row>". 
Set myCell = myTable.Cells.Item("3:1") 
Rem You could also use: 
Set myCell = myTable.Rows.Item(1).Cells.Item(3) 




Thanks,

Ole
Technical Details
Message-ID: <1de748fe.0@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!news-hub.siol.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <1de748fe.-1@WebX.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,d5e114e2c4c8795b
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-01-08 12:46:52 PST
From: "Olav Kvern" <okvern@adobe.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!news-hub.siol.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: Table inconsistency
Message-ID: <1de748fe.0@WebX.la2eafNXanI>
Date: Wed, 8 Jan 2003 12:30:58 -0800
References: <1de748fe.-1@WebX.la2eafNXanI>
Lines: 72
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit