Consulting

Results 1 to 3 of 3

Thread: Crop & Resize numerous images using VBA

  1. #1

    Crop & Resize numerous images using VBA

    Hi all,

    I have to capture many computer screen, and put it into one word file for my boss checking daily.
    I used to printscreen, paste to the Word, and manually crop and resize the pictures.

    I am self-studying VBA and just found the below VBA code from Microsoft which might be useful for me.
    https://docs.microsoft.com/zh-tw/off...ureformat.crop

    To fit my situation, i have made some adjustment as below.

    ---
    Sub CropNResize()


    Dim myInlineShape As InlineShape
    Dim myCrop As Crop

    Set myInlineShape = ActiveDocument.InlineShapes(1)
    Set myCorp = myInlineShape


    With myCorp
    .PictureFormat.CropLeft = 0
    .PictureFormat.CropTop = 60
    .PictureFormat.CropRight = 870
    .PictureFormat.CropBottom = 370
    .LockAspectRatio = True
    .Height = 293
    End With


    Set myInlineShape = ActiveDocument.InlineShapes(2)
    Set myCorp = myInlineShape


    With myCorp
    .PictureFormat.CropLeft = 0
    .PictureFormat.CropTop = 60
    .PictureFormat.CropRight = 870
    .PictureFormat.CropBottom = 370
    .LockAspectRatio = True
    .Height = 293

    End With
    End Sub


    Assuming if i have 100 pictures today, is there any method to cropNresize the images in few lines of command instead of repeating shape(1) shape(2)... shape(100)?
    Thanks a lot.

  2. #2
    Thanks all i have figured it out... though i still dont understand the logic and function of Dim....

    Sub CropNResize()
    
    
    Dim i As Long
    
    
    With ActiveDocument
    For i = 1 To .InlineShapes.Count
     With .InlineShapes(i)
    .PictureFormat.CropLeft = 0
    .PictureFormat.CropTop = 60
    .PictureFormat.CropRight = 870
    .PictureFormat.CropBottom = 370
    .LockAspectRatio = True
     .Height = 293
    End With
    Next i
    
    
    End With
    End Sub
    Last edited by Paul_Hossler; 08-03-2020 at 06:54 AM. Reason: CODE Tags

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    1. Welcome to the forum. Please take a minute and read the FAQs in the link in my sis=gnature

    2. I added CODE tags around your macro. You can use the [#] icon button next time. It sets it off and formats it

    3. 'Dim' (short for 'Dimension') is used to define a variable and give it a Type (Long in your example). Online help is pretty good for things like this. Using Dim is required if you use Option Explicit in your module
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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