首页 > 解决方案 > Insert Table Caption VBA Word

问题描述

I am trying to insert caption in the word table, but it seems that I have no control on parameter position. I looked at documentation and Position:=wdCaptionPositionAbove should write caption on the top of the table and Position:=wdCaptionPositionBelow should write at the bottom of the table. But I always get it on the same side with bellow recorded code. When I was recording code the captions were creatied in the right position.

Selection.InsertCaption Label:="Table", TitleAutoText:="InsertCaption3", _
        Title:="", Position:=wdCaptionPositionAbove, ExcludeLabel:=0
Selection.InsertCaption Label:="Table", TitleAutoText:="InsertCaption4", _
        Title:="", Position:=wdCaptionPositionBelow, ExcludeLabel:=0

I notice that caption will be written above if I manually create one caption and set it to above. But then I can't create caption bellow except if I manually create one caption bellow.

How can I set the position of the Caption (Bellow/Above the table) with VBA.

标签: vbams-word

解决方案


The MS help page on InsertCaption uses a specific Table range so it may be that your range does not correspond to a Table? To see the MS Help page for InsertCaption put the Cursor on 'InsertCaption in the VBA IDE and press F1.

Thus I'd suggest you try

Selection.Tables(1).Range.InsertCaption

推荐阅读