I have Table of Contents working fine. I can't get a Table Of Figures to work, however. I have tried setting the Caption property, but I still get "No Tables of Figures Entries Found". Anybody, HELP! Thanks.

Dani AI

Generated

Short summary: solved it by using Word’s InsertCaption call rather than trying to set the TablesOfFigures caption property, and ’s hint about drawing-layer objects is a good one to keep in mind. The common causes for "No Tables of Figures Entries Found" or a "Command failed" error when automating are (a) the InsertCaption call wasn’t targeting the actual image/shape (Selection/Range), (b) the wrong kind of shape was used (floating Shape vs InlineShape), or (c) the caption label argument was passed incorrectly from the automation client.

How it works (practical notes)

  • InsertCaption must be called against a Selection or a Range that contains the item you want to caption. If the selection is empty or not on the image, Word will fail or put the caption in the wrong place.
  • Images that are floating (Shapes) are not treated the same as inline images. Convert a floating Shape to an InlineShape first or target the shape’s anchor range before inserting the caption.
  • Use Word caption constants (for example wdCaptionFigure) when you can. If your automation language doesn’t expose those constants, pass the equivalent numeric value from the Word API.

Example (VBA) — shows the sequence to select an inline image, add a caption, then refresh the Table of Figures:

ActiveDocument.InlineShapes(1).Range.Select
Selection.InsertCaption Label:=wdCaptionFigure, Title:=" My caption text", Position:=wdCaptionPositionBelow
ActiveDocument.Fields.Update
ActiveDocument.TablesOfFigures(1).Update

Quick troubleshooting checklist

  • Make sure the selection/range actually contains the picture before calling InsertCaption.
  • If the picture is a floating Shape, convert it to inline (or use the anchor Range) and then caption.
  • If automating from another language, pass the caption-label constant or its numeric equivalent.
  • After inserting captions, update fields and the TableOfFigures.
  • If unsure, record a macro in Word while doing the steps manually and compare the generated VBA to your automation calls.

This complements the thread: follow ’s discovery about using InsertCaption and keep ’s drawing-layer caveat in mind when images are not inline.

Recommended Answers

All 12 Replies

Which version of MS Word are you using, 2007 or 2010?

Also have a look at THIS link, might contain your answer.

I am developing for either. To this point, I have been careful to only use methods that are available in both.

Did you have a look at the link I gave, you might have missed something when trying to set the caption.

I just read the link you provided, which I have seen before. It speaks only to the "manual" method. I am aware that I can record a macro and review it, but seeing a few lines of sample code is so much more informative as you have to separate all that you don't need from that which you do when looking at macros.

Ahh, more information. :)

So you are trying to set the caption via a macro right? If so, show the code you are using and where the error occurred.

Sorry, the title of my post included "Word Automation", and I am using the automation object.

No, I am actually using the Progress ABL to drive the MSWORD.OLB object. I create the TOF point at the top of the document creation, just like I do for the TOC. I update the TOF at the end, just like I do the TOC. The Table of Contents works great. I just cannot identify the right method for saying that "this text here is one of my captions". I looked at the caption method, but although I get no errors, it does nothing.

To setup the TOF:
chwordapplication:SELECTION:TypeParagraph().

To set a caption (not working):
chDoc:TablesOfFigures:ITEM(1):caption = "My Caption".

To update the TOF (generates the No Tables of Figures Entries Found):
chTOF = chDoc:TablesOfFigures:ITEM(1).
chTOF:UPDATE().

I am sorry to say that this is out of my depth. Never worked with tables of figures.

It might be that the entries is in the drawing layer and not in the floating object. See for more info. Other than that, sorry I can't be of more help.

Interesting, but I used the "record macro" method and found that the InsertCaption method is apparently the method to use on the SELECTION or RANGE object. Fine, but now I get an error "Command Failed" (great message), with error code 0x80020009. Not finding much that helps on the web with that error.

Resolved... the first argument to InsertCaption has to be a numeric like -1 to indicate the table (figures, graphs, etc.). The 2nd argument is the string. Thanks for trying.

commented: Sorry I couldn't do more... +12

Sorry I couldn't do more. Glad you could solve it though. Some kudos. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.