View Single Post
 
Old 10-18-2015, 04:17 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Quote:
Originally Posted by FaizanRoshan View Post
i don't want to change h & w in code for each cells as i mention that all the cells have different size.
The code you've already posted doesn't require any foreknowledge of the cell height or width - for every table in the document. Have you tried running it?

Your code could be made more efficient, though:
Code:
Sub FitPics()
Application.ScreenUpdating = False
Dim Tbl As Table, iShp As InlineShape
With ActiveDocument
  For Each Tbl In .Tables
    For Each iShp In Tbl.Range.InlineShapes
      With iShp
        .LockAspectRatio = msoTrue
        .Height = .Range.Cells(1).Height
        If .Width > .Range.Cells(1).Width Then
          .Width = .Range.Cells(1).Width
        End If
      End With
    Next
  Next
End With
Application.ScreenUpdating = True
End Sub
Still, if you insert the pictures directly into the table cells via Insert|Picture, you don't even need a macro...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]