Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 707
  • Last Modified:

Select all images via VBA code or else...

Hi, I have a big word document with a lot of same images. I want to select all images and redimension them with the same way and do not redimension each one of them (because they are about 14.000!!). I think that this can be done via vba code (macro) but how? Else, is there other method? The doc is the result of a mail merge with different image (but with the same wrong dimensions) in each page and there isn't a way to change the dimension to the image merge field before the merge.
0
Non-Linear
Asked:
Non-Linear
  • 5
  • 3
  • 2
1 Solution
 
Eric FletcherCommented:
If the entire document is being generated by mail merge, and you want all images to be the same dimension, you can constrain the image size by setting them within a table in the merge document (even a one-cell table will do) and turning off the "Automatically resize to fit contents" table option (Options... button of Table Properties). Incoming images will be sized to fit the table.

If possible, consider using the INCLUDEPICTURE field with the \d switch to insert the images as a link to the originals. With that many images, inserted images will make the file very large; as linked images, it would be quite manageable.
0
 
GrahamSkanRetiredCommented:
How many images are there in the Main document? It might be easier to change the dimensions in the Main document and then rerun the merge.
0
 
GrahamSkanRetiredCommented:
Well done, Eric. I'm leaving the next one for you. It's about styles.
0
[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 
Eric FletcherCommented:
LOL Graham! We must operate on very similar schedules -- even though there is a big gap in our time zones. I have EE open in a multi-tabbed Firefox browser on my right monitor, and pop over to it every so often as I work in Word (or whatever) on the left one.

Non-Linear: When you say "a lot of same images" in your question, do you mean the 14K images are not 14K different ones? If so, inserting them as links will be even more efficient. As an alternative approach, is there any way you can "pre-process" the images to resize them and save them with the same name into a different directory? Many image management programs can do this as a batch routine. This way, you would have them in the size you want, but would not be altering the originals.
0
 
GrahamSkanRetiredCommented:
It seems so, Eric.

I try to service questions that I have already commented on before looking for fresh ones. Also, today I was trying to fix my own 'missing NTLDR' problem, so I was even later than usual in getting started. My Firefox is open in my left monitor.

Non-Linear, please excuse our by-conversation.
We haven't answered your question directly.

It would be possible to devise a macro to do that, but it may not be the best way and more details would be needed
0
 
Non-LinearAuthor Commented:
Erick's idea about one cell table smells good I'll try it...
Graham...I have only one image in the main document and after the merge the image is different for each one page. I can't change the dimensions in main document because there isn't an image frame or box that I put the image. I use the {INCLUDEPICTURE {MERGEFIELD Path}} and this is not visual. I need a vissually way to change the dimension in the main document (that will affect the merged document later) or in the merged document.I think that the Erick's tricky idea is good but I have to try first and I'll reply soon...
The second idea about pre-process the images is good but this is not a visually way incorporated to the word document so that I can see the result immediately. If the pre-process is not the right then I have to pre-process again and again...because I can't know how these changes will appear in the document.
0
 
GrahamSkanRetiredCommented:
This macro to run on the result document might help, though I'm not sure if it matches your criterion about being visual.

Sub ResizePictures()
    Dim ilsh As InlineShape
    For Each ilsh In ActiveDocument.InlineShapes
         
        'ilsh.LockAspectRatio = msoTrue
        'Locking the aspect ratio doesn't seem to work on my system, so I set it to false
        'and adjust both height and width
        ilsh.LockAspectRatio = msoFalse
       
        ilsh.Width = ilsh.Width / 2
        ilsh.Height = ilsh.Height / 2
    Next ilsh
End Sub
 
0
 
Non-LinearAuthor Commented:
Ok I think that we are in a good way...
Look...The idea with cell is working (the same with a text box) but there is a problem with the Lock aspect ratio property of the images. This property is checked by default and when I change the height of the cell (or text box) then the height of the image that appear changes but also it changes the width of the image and this is not what I want.
0
 
GrahamSkanRetiredCommented:
That's ironic. My code had the opposite problem.
0
 
Non-LinearAuthor Commented:
Yes...it is
But I think that I will solve my problem exactly as I want and Graham is the reason...or the code that Graham has written. I want to change the width and height of all images one pixel at a time independently. I will create four macros with a button for each one and with this way I will have visually results...I will try and I will be back
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now