18 Replies Latest reply on Mar 16, 2010 9:47 AM by TonyTuneson

    TableStyles.Count returns error (VB)

    TonyTuneson

      myInDesign.ActiveDocument.TableStyles.Count   - returns an error: Type mismatch.

      i = myInDesign.DoScript("app.activeDocument.tableStyles.count", idJavascript)
      Does not work either

       

      myInDesign.ActiveDocument.TableStyles.Item(1)   - returns an error

      myInDesign.DoScript("app.activeDocument.tableStyles.item(1)", idJavascript)    - returns "[Basic Table]"

       

      What's going on here? Any ideas please...? I'd like to make it work in VB.

        • 1. Re: TableStyles.Count returns error (VB)
          [Jongware] Most Valuable Participant

          What's going on is the difference between a property and a function.

           

          "count" is a function -- therefore, you need to use it like one: count()

           

          You probably got it confused with the array property "length".

          • 2. Re: TableStyles.Count returns error (VB, CS3)
            Tony Tuneson Level 1

            Thanks for the suggestion, but that part does not seem to be the problem. Please see below examples and the workaround I found.

             

            Examples:

            Buf = myIDDoc.TableStyles.Item(1)   > returns a "Type Mismatch" error (? Buf is declared as a String; also error with.Name property)

            i = MyIDDoc.TableStyles.Count         > returns a "Type Mismatch" , while e.g.

            i = MyIDDoc.ParagraphStyles.Count  > works as expected

             

            I could not use the "count" function via JS either. However I discovered that I can read all items via JS by manually increasing the index until an error occurs.

            This workaround reads (and counts) all available TableStyles from the active document and puts them in a combobox:

             

            tsCount = 1
            On Local Error Resume Next
            Buf = myInDesign.DoScript("app.activeDocument.tableStyles.item(" + CStr(tsCount) + ")", idJavascript)

            Do While Err = 0
                TableStyleCombo.AddItem Buf
                tsCount = tsCount + 1
                Buf = myInDesign.DoScript("app.activeDocument.tableStyles.item(" + CStr(tsCount) + ")", idJavascript)
            Loop

            tsCount = tsCount - 1

            On Local Error GoTo 0

             

            Probably something that really only occurs on my machine (again). I never heard of a partly corrupted library, but who knows...

            • 3. Re: TableStyles.Count returns error (VB, CS3)
              AdobeScripts Level 3

              This works perfectly fine in ID CS3 - 5.0.4 - have you installed all updates ?

               

              set myindi=createobject("InDesign.Application")
              set mydoc=myindi.activedocument

               

              msgbox("CellStyles Count = " & mydoc.CellStyles.count)
              msgbox("TableStyles Count = " & mydoc.TableStyles.count)
              msgbox("ParaStyles Count = " & mydoc.ParagraphStyles.count)

              Tony Tuneson wrote:

               

              Thanks for the suggestion, but that part does not seem to be the problem. Please see below examples and the workaround I found.

               

              Examples:

              Buf = myIDDoc.TableStyles.Item(1)   > returns a "Type Mismatch" error (? Buf is declared as a String; also error with.Name property)

              First - you can't assign like this - you need to use SET:

               

              Set Buf = myIDDoc.TableStyles.Item(1)

               

              Second - you can't assign TableStyle type to String type.

              i = MyIDDoc.TableStyles.Count         > returns a "Type Mismatch" , while e.g.

              i = MyIDDoc.ParagraphStyles.Count  > works as expected

              What version of ID do you have - 5.0.x ?

               

              robin

              www.adobescripts.co.uk

              • 4. Re: TableStyles.Count returns error (VB, CS3)
                TonyTuneson Level 1

                Thanks for your suggestions. To pinpoint the problem and ignore assignment and type conversion problems:

                 

                This works fine:

                MsgBox "ParaStyles Count = " & Format(myDoc.ParagraphStyles.Count)
                MsgBox myDoc.ParagraphStyles.Item(1).Name

                 

                This gives errors on both lines (Type mismatch, same as the CellStyles):

                MsgBox "TableStyles Count = " & Format(myDoc.TableStyles.Count)
                MsgBox myDoc.TableStyles.Item(1).Name

                /Help/About InDesign... Version 5.0.4

                 

                As said, the DoScript (JavaScript) call to read myDoc.TableStyles.Item(1).Name works fine.

                • 5. Re: TableStyles.Count returns error (VB, CS3)
                  AdobeScripts Level 3

                  Trash your preferences - press and hold CTRL+SHIFT+ALT when InDesign boot.

                   

                  robin

                  www.adobescripts.com

                  • 6. Re: TableStyles.Count returns error (VB, CS3)
                    TonyTuneson Level 1

                    Preferences trashed, still the same erratic behavior.

                    • 7. Re: TableStyles.Count returns error (VB, CS3)
                      AdobeScripts Level 3

                      TonyTuneson wrote:

                       

                      Preferences trashed, still the same erratic behavior.

                      How you run your scripts ?

                      By VisualBasic 6 IDE, as VisualBasic Scripts (from InDesign Script Panel) or maybe you use .NET ?

                       

                      robin

                      www.adobescripts.com

                      • 8. Re: TableStyles.Count returns error (VB, CS3)
                        TonyTuneson Level 1

                        Both in VB6 IDE and as .exe they give the same errors.

                        Out of curiosity I ran it as a script: NO errors...!

                        • 9. Re: TableStyles.Count returns error (VB, CS3)
                          AdobeScripts Level 3

                          TonyTuneson wrote:

                           

                          Both in VB6 IDE and as .exe they give the same errors.

                          Out of curiosity I ran it as a script: NO errors...!

                          You need to check - in VB6 IDE - which TLB file you have selected in F2 - REFERENCES list.

                          Adobe Installer and updater put two TLB files for each InDesign

                          One in "C:\ProgramData\..." and second in "C:\Users\..." - second must be newer.

                           

                          robin

                          www.adobescripts.com

                          1 person found this helpful
                          • 10. Re: TableStyles.Count returns error (VB, CS3)
                            TonyTuneson Level 1

                            Hi Robert,

                             

                            Thanks very much for your helpful suggestions. You're right, timestamps of the TLBs differ. I tried earlier to select the other one in the IDE, to no avail.

                            I now replaced the old TLB with the newer one, but it makes no difference.

                             

                            But I think I found something:
                            As long as I leave OUT the declaration for myDoc ("Dim myDoc As InDesign.Document"), the CellStyles.Count line works fine....!!!

                             

                            It also works fine when I declare myDoc as Object:

                             

                            Dim myDoc as Object

                            Set myDoc = myIndi.ActiveDocument

                            MsgBox "CellStyles Count = " & Format(myDoc.CellStyles.Count)

                             

                            It's nice to know this Object-workaround, but using the correct type declaration does have advantages.

                            MsgBox TypeName(myDoc) states that the Object "myDoc" is of type "Document" - then why can't it be declared accordingly?

                             

                            Can you replicate this behavior on your system?

                            • 11. Re: TableStyles.Count returns error (VB, CS3)
                              AdobeScripts Level 3

                              This is example of my declarations:

                               

                              Dim myInDi As InDesign.Application
                              Dim myDoc As InDesign.Document
                              Dim myStory As InDesign.Story
                              Dim myPara As InDesign.Paragraph
                              Dim myTF As InDesign.TextFrame

                              ...

                              Set myInDi = CreateObject("InDesign.Application.CS4")
                              Set myDoc = myInDi.ActiveDocument

                               

                              I have never ever had any problems with this ...

                               

                              robin

                              www.adobescripts.com

                              • 12. Re: TableStyles.Count returns error (VB, CS3)
                                TonyTuneson Level 1

                                I also wrote thousands line of 'strictly typed' code, with Dim Statements, without problems. (In some other problematic cases I think I just don't fully understand the logic behind the ID DOM.)

                                 

                                Just for CellStyles and TableStyles some obvious functions don't work.

                                For my info: can you confirm that you can run the code below without errors from VB6 IDE or an .exe?

                                 

                                Dim myInDi as InDesign.Application

                                Dim myDoc as InDesign.Document

                                Set myInDi = CreateObject("InDesign.Application.CS3")
                                Set myDoc = myInDi.ActiveDocument

                                MsgBox "CellStyles Count = " & Format(myDoc.CellStyles.Count)

                                 

                                Note that in my code it's CS3, not CS4 as in your examples. Maybe a conflict with a CS2 library on my system?

                                 

                                I now remember a similar thing (off-topic); I had to use the following JS-DoScript lines, because they generated errors when called in the regular VB-way.

                                    myIndesign.DoScript "app.importedPageAttributes.pageNumber = " + CStr(Pageorder(PageCounter)), idJavascript
                                    myIndesign.DoScript "app.importedPageAttributes.importedPageCrop= ImportedPageCropOptions.CROP_BLEED", idJavascript

                                • 13. Re: TableStyles.Count returns error (VB, CS3)
                                  AdobeScripts Level 3

                                  TonyTuneson wrote:

                                   

                                  I also wrote thousands line of 'strictly typed' code, with Dim Statements, without problems. (In some other problematic cases I think I just don't fully understand the logic behind the ID DOM.)

                                   

                                  Just for CellStyles and TableStyles some obvious functions don't work.

                                  For my info: can you confirm that you can run the code below without errors from VB6 IDE or an .exe?

                                  ID_CS3_bug.png

                                   

                                  Do you have this problem ALWAYS ? With old and new scripts ?

                                   

                                  And fundamental question what Windows Version you have installed NOW ?

                                   

                                  robin

                                  www.adobescripts.com

                                  1 person found this helpful
                                  • 14. Re: TableStyles.Count returns error (VB, CS3)
                                    TonyTuneson Level 1

                                    Unbelievable screenshot!

                                     

                                    It's the first time I use TableStyles and CellStyles.

                                    I never had a problem that used to work before and suddenly doesn't anymore. In that case I know it's my own fault somehow. If I get something to work with a workaround I usually go on to the next project. There are so many things that seem inconsistent in the InDesign DOM that I don't want too much time about it anymore. But this one intrigues me.

                                     

                                    Maybe I must try to remove the CS2 Suite (or references), but then I'm afraid I'll lose Acrobat as well.

                                     

                                    My OS is Windows Vista Business, SP2

                                    (32-Bit)

                                    • 15. Re: TableStyles.Count returns error (VB, CS3)
                                      AdobeScripts Level 3

                                      TonyTuneson wrote:

                                       

                                      Unbelievable screenshot!

                                      Why ?

                                      There are so many things that seem inconsistent in the InDesign DOM ...

                                      no comments

                                      Maybe I must try to remove the CS2 Suite (or references), but then I'm afraid I'll lose Acrobat as well.

                                      I have ID 2.0.2, CS1, CS2, CS3, CS4 - all together on the same Vista 64bit - with PS and IL for each CSx version - and no problems at all.

                                      My OS is Windows Vista Business, SP2 (32-Bit)

                                      I have only SP1 installed on Vista Home Premium 64bit ...

                                       

                                      robin

                                      www.adobescripts.com

                                      • 16. Re: TableStyles.Count returns error (VB, CS3)
                                        TonyTuneson Level 1

                                        Hi Robin,

                                         

                                        I fear we're stuck then. It is something local on my system only. It just doesn't make sense, that's why I found the screenshot unbelievable.

                                         

                                        Sorry about my remark about InDesign DOM, I didn't mean to offend anybody. It works great and is extremely productive, but sometimes... Arrgh... it just makes me struggle.

                                         

                                        And now? Do you have other suggestions that I could try (except "re-install Windows" or  "install everything on another system and try again.")?

                                        Close this thread? Involve some serious debugging?

                                         

                                        Thanks again for your involvement!

                                         

                                        Anton.

                                        • 17. Re: TableStyles.Count returns error (VB, CS3)
                                          AdobeScripts Level 3

                                          TonyTuneson wrote:

                                           

                                          Sorry about my remark about InDesign DOM, I didn't mean to offend anybody. It works great and is extremely productive, but sometimes... Arrgh... it just makes me struggle.

                                          It wasn't addressed to you

                                          And now? Do you have other suggestions that I could try (except "re-install Windows" or  "install everything on another system and try again.")?

                                          Try to add new user in system.

                                          Thanks again for your involvement!

                                          You are welcome

                                           

                                          robin

                                          www.adobescripts.co.uk

                                          • 18. Re: TableStyles.Count returns error (VB, CS3)
                                            TonyTuneson Level 1

                                            hi Robin,

                                             

                                            I tried it again as administrator and I created a new user. Still the same results:

                                            myDoc.CellStyles.Count

                                            WITHOUT using a Dim myDoc as Document, the CellStyles.Count works fine.

                                            It also works fine if i Dim myDoc as Object.

                                             

                                            What also works (strange enough):

                                            set myIndi = CreateObject("InDesign.Application")

                                            msgbox format(myIndi.CellStyles.Count)

                                             

                                            I assume it takes the active doc...

                                            But the same here: if myIndi is declared as InDesign.Application -> Type mismatch error