🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #19012

Re: "row" on page 1 or on page 2? Is there a way?

#19012
From: Olav Kvern
Date: Mon, 27 Jan 2003 20:31
63 lines
3495 bytes
Armin--

There's no way that I can think of to find the page containing a given cell by climbing the "parent" hierarchy--as you've discovered, the parent of the cell is the table, the parent text frame of the table is the first text frame of the table.

That said, I can think of a number of ways to find the page containing the cell. All of them, unfortunately, involve adding text and duplicating objects--which I'd rather not do. But I haven't thought of a way around it. Here's the best approach I've come up with so far:



Private Sub Command1_Click() 
Dim myInDesign As InDesign.Application 
Set myInDesign = CreateObject("InDesign.Application.2.0") 
Rem Clear the find/change attributes. 
myInDesign.FindPreferences = idNothing 
myInDesign.ChangePreferences = idNothing 
Set myDocument = myInDesign.ActiveDocument 
Rem Get a reference to an example cell. 
Set myCell = myDocument.Stories.Item(1).Tables.Item(1).Rows.Item(15).Cells.Item(1) 
Rem Enter some unique string to search for (keep it relatively short, so that the cell won't be pushed to another page). 
myFindString = "!!" 
Rem Enter the string in the cell. 
myCell.InsertionPoints.Item(1).TextContents = myFindString 
Rem Find the page number. 
myPageNumber = myFindCellParentPage(myDocument, myFindString) 
If myPageNumber <> "Not found" Then 
    MsgBox "Cell appears on page " & CStr(myPageNumber) 
Else 
    MsgBox "Cell was not found." 
End If 
Rem Now clean up the text we entered in the cell. 
For myCounter = 1 To Len(myFindString) 
    myCell.Characters.Item(1).Delete 
Next 
Rem And do whatever it is you want to do with the page number. 
End Sub 
Private Function myFindCellParentPage(myDocument, myFindString) 
For myPageCounter = 1 To myDocument.Pages.Count 
    Set myPage = myDocument.Pages.Item(myPageCounter) 
    For myTextFrameCounter = 1 To myPage.TextFrames.Count 
        Set myTextFrame = myPage.TextFrames.Item(myTextFrameCounter) 
        Set myNewTextFrame = myTextFrame.Duplicate 
        Set myFoundItems = myNewTextFrame.Search(myFindString, False, False) 
        If myFoundItems.Count <> 0 Then 
            Rem Found the text, so the page containing the cell is the parent of myNewTextFrame 
            myPageNumber = myNewTextFrame.Parent.Name 
            myNewTextFrame.Delete 
            myFindCellParentPage = myPageNumber 
            Exit Function 
        Else 
            myNewTextFrame.Delete 
        End If 
    Next 
Next 
myFindCellParentPage = "Not found" 
End Function 




You should be able to take this function and add it to your project. All it needs is a reference to a cell and a document.

Thanks,

Ole
Technical Details
Message-ID: <1de78f51.0@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!logbridge.uoregon.edu!xmission!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <1de78f51.-1@WebX.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,7203538a108a08cc
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-01-27 12:38:08 PST
From: "Olav Kvern" <okvern@adobe.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!logbridge.uoregon.edu!xmission!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: "row" on page 1 or on page 2? Is there a way?
Message-ID: <1de78f51.0@WebX.la2eafNXanI>
Date: Mon, 27 Jan 2003 12:31:10 -0800
References: <1de78f51.-1@WebX.la2eafNXanI>
Lines: 70
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit