View Single Post
 
Old 02-19-2012, 01:17 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,385
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Marrick,

Try:
Code:
Sub ApplyCaptions()
Application.ScreenUpdating = True
Dim oCap As CaptionLabel, bCap As Boolean, iShp As InlineShape, oTbl As Table, TmpRng As Range
With ActiveDocument
  For Each iShp In .InlineShapes
    Set TmpRng = iShp.Range.Paragraphs.First.Range
    With TmpRng
      If .Style = "Caption" Then bCap = ChkCaption(TmpRng)
      If .Paragraphs.Last.Next.Range.Style = "Caption" And bCap = False Then
        bCap = ChkCaption(TmpRng)
      End If
      If bCap = False Then
        iShp.Range.InsertCaption Label:="Figure", TitleAutoText:="", _
          Title:="", Position:=wdCaptionPositionBelow, ExcludeLabel:=0
      End If
    End With
  Next
  For Each oTbl In .Tables
    Set TmpRng = oTbl.Range.Paragraphs.Last.Range
    With TmpRng
      If .Style = "Caption" Then bCap = ChkCaption(TmpRng)
      If .Paragraphs.Last.Next.Range.Style = "Caption" And bCap = False Then
        bCap = ChkCaption(TmpRng)
      End If
      If bCap = False Then
        oTbl.Range.InsertCaption Label:="Table", TitleAutoText:="", _
          Title:="", Position:=wdCaptionPositionBelow, ExcludeLabel:=0
      End If
    End With
  Next
End With
Set TmpRng = Nothing
Application.ScreenUpdating = False
End Sub
 
Function ChkCaption(TmpRng As Range) As Boolean
Dim oCap As CaptionLabel
ChkCaption = False
For Each oCap In CaptionLabels
  If InStr(TmpRng.Text, CaptionLabels(oCap)) > 0 Then
    ChkCaption = True
    Exit For
  End If
Next
End Function
Depending on the # of tables & inlineshapes, this might take a while.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote