Consulting

Results 1 to 3 of 3

Thread: Macro for resize and crop picture with different size of table cells in word

  1. #1

    Macro for resize and crop picture with different size of table cells in word

    I have macro code that take picture form folder and insert it in word table cell, and then crop it.
    Now i have many table cells in Ms Word with different size. i want to make some change in code so that it resize and crop pictures auto with the size of table cells. Table cells never change its size.
    Here is code:

    Sub FitPics()
    Application
    .ScreenUpdating =False
    Dim Tbl As Table, Ishp As InlineShape
    With ActiveDocument
    ForEach Tbl In.Tables
    ForEach Ishp In Tbl.Range.InlineShapes
    With Ishp
    .LockAspectRatio = msoTrue
    If.Height >.Range.Cells(1).Height Then
    .Height =.Range.Cells(1).Height
    EndIf
    If.Width >.Range.Cells(1).Width Then
    .Width =.Range.Cells(1).Width
    EndIf
    If.Width <.Range.Cells(1).Width Then
    .Width =.Range.Cells(1).Width
    EndIf
    EndWith
    Next
    Next
    EndWith
    Application
    .ScreenUpdating =True
    EndSub

  2. #2
    VBAX Newbie
    Joined
    Nov 2015
    Posts
    2
    Location
    In the above code is a syntax error!
    Does anybody has a solution?
    Thx

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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
           If .Height > .Range.Cells(1).Height Then
             .Height = .Range.Cells(1).Height
           End If
           If .Width > .Range.Cells(1).Width Then
             .Width = .Range.Cells(1).Width
           End If
           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
    Greg

    Visit my website: http://gregmaxey.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •