View Single Post
 
Old 09-04-2013, 02:34 AM
ragesz ragesz is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Oct 2012
Posts: 14
ragesz is on a distinguished road
Default

Thank you fumei!

It works well with tables! I already had captions without label and number for my tables so I signed them with special characters (#table_caption_start# /...end#) then I searched these caption (With Selection.Find .Execute FindText:="#table_caption_start#",...) and used it at InsertCaption at Title.

Here is the code:
Code:
Sub addTableCAP2()
Dim objTable As Table
Dim rngTable As Range
Dim strTable As String
For Each objTable In ActiveDocument.Tables
  With Selection.Find
    .Execute FindText:="#table_caption_start#", Forward:=True, MatchWholeWord:=False, _
    MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False
    Set rngTable = Selection.Range
    rngTable.End = ActiveDocument.Range.End
    rngTable.End = rngTable.Start + InStr(rngTable, "end#")
    rngTable.End = rngTable.End + 4
    strTable = Replace(rngTable.Text, "#table_caption_start#", "")
    strTable = Replace(strTable, "#table_caption_end#", "")
    strTable = Left(strTable, Len(strTable) - 1)
    rngTable.Text = ""
    objTable.Select
    Selection.InsertCaption Label:="Table", TitleAutoText:="", Title:=" - " + strTable, _
    Position:=wdCaptionPositionAbove
  End With
Next
End Sub
Reply With Quote