2 Replies Latest reply on Dec 5, 2010 3:00 PM by Jarema_IV


      I am scripting InDesign CS3 using VB Script in the MS Windows environment.

      My objective is to add Hyperlinks to images so exported PDFs expose the links. The images are each placed in a table cell.

      I can not determine the correct use of the HyperlinkPageItemSources.Add method syntax.

      ***** CODE IN QUESTION *******

      Set oCell = oRow.Cells.Item(intCellNum)
      oCell.InsertionPoints.FirstItem.Place ("ImagePath\FileName")
      Set oRectangle = oCell.AllGraphics.FirstItem.Parent

      ' the next line gets Run-time Error '13': Type mismatch

      Set oHyperlinkPageItemSource = oDocument.HyperlinkPageItemSources.Add(oRectangle)

      Set oHyperlinkURLDestination = oDocument.HyperlinkURLDestinations.Add("http://www.desired_link.com")

      Set oHyperlink = oDocument.Hyperlinks.Add(oHyperlinkPageItemSource, oHyperlinkURLDestination)

      ***** END OF CODE IN QUESTION *******

      I believe oRectangle (Dim oRectangle As InDesign.Rectangle) is an InDesign PageItem which I believe is the requirement for the .Add method.

      Is this a bug or does my code need correcting?

      Any help appreciated. Thank you.
        • 1. Re: HyperlinkPageItemSources

          I am back answering my own problem (after much time).


          I found the function ?typename( ) most useful in determining the class of the entity placed insided the parens. This is an immediate window feature.


          Most of the issues I have found with the errors are "data mismatch" and the typename function helps determine what kind of entity you are dealing with. Combining the information from the Object Browser (F2 key) helps determine what type of entity each method is looking for.


          Looking at my current code, it is successfully working the theHyperlinkTextSources instead of the HyperlinkPageItemSources method.


          In this example a graphic has been inserted into a text frame object, and the link is to appear on the graphic.


              oTextframe.InsertionPoints.LastItem.Place (sImage & ".tif")



              Set oHyperlinkTextSource = oDocument.HyperlinkTextSources.Add(oTextframe.Texts.FirstItem)


          The key thing is supplying the correct data type to satisfy the method.

          • 2. Re: HyperlinkPageItemSources

            Well, nice idea but not a solution.

            I got the same problem with VB and CS5. I try to do something like that:


            Dim mInDesign As InDesign.Application

            Dim mPub As InDesign.Document
            Dim mHyperlink As InDesign.Hyperlink


            Set mInDesign = GetObject("", "InDesign.Application.CS5")
            Set mPub = mInDesign.Documents.Item(1)

            Dim mRectangle as InDesign.Rectangle

            'REM - rectangleID is a Long parameter for this function and is a valid rectangle ID

            Set mRectangle=mPub.Rectangles.ItemById(rectangleID)

            Dim mHysperSource As InDesign.HyperlinkPageItemSource
            Set mHysperSource = mPub.HyperlinkPageItemSources.Add(mRectangle)

            Dim mDestination As InDesign.HyperlinkURLDestination
            Set mDestination = mPub.HyperlinkURLDestinations.Add(mDocObj.rs.fields(mQuellDBField).Value)


            Set mHyperlink = mPub.Hyperlinks.Add(mHysperSource, mDocObj.rs.fields(mQuellDBField))
            mHyperlink.Visible = True


            Well, the bold underlined line of code creates error 13 - type mismatch!

            No mather what I am trying to use mRectangle.AllPageItems.Item(1), mRectangle.PageItems.Item(1), mRectangle.AllGraphics.Item(1) - still no success


            Watching the variable shows mRectangle as Variant/Object/Rectange and mRectangle.AllGraphics.Item(1) as Variant/Object/Image

            The Image is a JPEG Image....


            Any suggestions how to get Hyperlinks working with Rectnagle? (I cannot use TextFrame with InsertionPoint... it is Rectangle and I cannot change it)