We help IT Professionals succeed at work.

Select all images via VBA code or else...

Non-Linear
Non-Linear asked
on
Medium Priority
741 Views
Last Modified: 2008-02-01
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.
Comment
Watch Question

CERTIFIED EXPERT

Commented:
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.
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
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.
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
Well done, Eric. I'm leaving the next one for you. It's about styles.
CERTIFIED EXPERT

Commented:
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.
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
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

Author

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.
Retired
CERTIFIED EXPERT
Top Expert 2012
Commented:
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
 

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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.
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
That's ironic. My code had the opposite problem.

Author

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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.