View Single Post
 
Old 01-26-2018, 01:51 PM
hysterical.useless hysterical.useless is offline Windows 10 Office 2016
Novice
 
Join Date: Jan 2018
Posts: 12
hysterical.useless is on a distinguished road
Default Import images, resize them, and fit them to specific locations on the page

I am trying to create a macro that, when activated, imports a specific number of images from a designated folder, resizes them to specific dimensions, and places them at specific coordinates on the page (within tables, actually). The name of the image governs how they are imported into the document. For example, an image named "1" will be imported, resized, and relocated to a specific spot, an image named "2" will be imported, resized, and relocated to a different spot, and so forth.

I've been researching how to do this in Word, but am surprised that I haven't come across any solutions yet. The fact that Word disables the ability to import images when in "Record Macro" mode has been a huge roadblock for me, since I am not great at writing VBA freehand.

I was able to get a similar macro working in Excel using this VBA code, but I really need to do this in Word, not Excel. Here is some code from my Excel macro:

Code:
Sub MovePictures()

    'Page 1, Picture 1

    ActiveSheet.Pictures.Insert("[Image Filepath Here]") _
        .Select
    Selection.ShapeRange.Width = 92.16
    Selection.ShapeRange.IncrementLeft -360
    Selection.ShapeRange.IncrementTop 75.75
    
    
    'Page 1, Picture 2
    
    ActiveSheet.Pictures.Insert("[Image Filepath Here]") _
        .Select
    Selection.ShapeRange.Width = 89.28
    Selection.ShapeRange.IncrementLeft -478.5
    Selection.ShapeRange.IncrementTop 574
    
    'Page 1, Picture 3
    
    ActiveSheet.Pictures.Insert("[Image Filepath Here]") _
        .Select
    Selection.ShapeRange.Width = 182.88
    Selection.ShapeRange.IncrementLeft -709.5
    Selection.ShapeRange.IncrementTop 473.25
    
    'Page 1, Picture 4
    
    ActiveSheet.Pictures.Insert("[Image Filepath Here]") _
        .Select
    Selection.ShapeRange.Width = 184.32
    Selection.ShapeRange.IncrementLeft -515.25
    Selection.ShapeRange.IncrementTop 472

End Sub
I achieved this in Excel by turning on the "Record Macro" feature and, one at a time, importing all images from a specific cell location, resizing them from that location, then moving them to the appropriate spots with my arrow keys so I could calculate the exact IncrementLeft and IncrementTop coordinates for each image. Unfortunately, I don't think this same approach will work for Word, given the more rigid nature of a Word document relative to using images.

Any help would be very much appreciated!
Reply With Quote