Consulting

Results 1 to 4 of 4

Thread: Macro to crop pictures

  1. #1
    VBAX Newbie
    Joined
    Nov 2020
    Posts
    2
    Location

    Macro to crop pictures

    Quote Originally Posted by gmaxey View Post
    I was just introducing you to some of the controls. Here is the fish.

    Lets say you have a 1/2 white border around the image.

    [VBA]Sub CropDemo()
    Dim oILS As InlineShape
    Set oILS = Selection.InlineShapes(1)
    With oILS
    .PictureFormat.CropLeft = 36
    .PictureFormat.CropTop = 36
    .PictureFormat.CropRight = 36
    .PictureFormat.CropBottom = 36
    End With
    With oILS
    .LockAspectRatio = True
    .Height = 360
    End With
    lbl_Exit:
    Exit Sub
    End Sub
    [/VBA]
    I want to crop all the pictures at once in my document. Please help
    Last edited by macropod; 11-18-2020 at 01:24 PM. Reason: Split to new thread & merged first two posts

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,247
    Location
    You would start by writing some code. Something like this would be helpful:

    For Each oILS In ActiveDocument.InlineShapes
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Newbie
    Joined
    Nov 2020
    Posts
    2
    Location
    Quote Originally Posted by gmaxey View Post
    You would start by writing some code. Something like this would be helpful:<br>
    <br>
    For Each oILS In ActiveDocument.InlineShapes
    <br>

    I tried this but got error "Compile error: For without next"
    Sub Crop()
    Dim oILS As InlineShape
    Set oILS = Selection.InlineShapes(1)
    For Each oILS In ActiveDocument.InlineShapes
    With oILS
    .PictureFormat.CropLeft = 36
    .PictureFormat.CropTop = 36
    .PictureFormat.CropRight = 36
    .PictureFormat.CropBottom = 36
    End With
    With oILS
    .LockAspectRatio = True
    .Height = 360
    End With
    lbl_Exit:
    Exit Sub
    End Sub

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,247
    Location
    That would imply that you are missing the Next statement. If you do something "For" one item in a collections then when done, you would want to do it for the Next item in the collection.

    For Each ...
    'Do something
    Next

    You also don't need the the Set oILS statement in the above code.
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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