#1
|
|||
|
|||
Apply Picture formatting to all pictures in the word file
Hello,
I have a word file with hundreds of images in it. I want to apply the following formatting to all the pictures in the word file: Brightness +40% Contrast +40% Could you please advise how to do this? Thank you very much for your help. |
#2
|
||||
|
||||
For that you might use a macro like:
Code:
Sub Demo() Application.ScreenUpdating = False Dim i As Long With ActiveDocument For i = 1 To .Shapes.Count With .Shapes(i).PictureFormat .Brightness = .Brightness + 0.4 .Contrast = .Contrast + 0.4 End With Next For i = 1 To .InlineShapes.Count With .InlineShapes(i).PictureFormat .Brightness = .Brightness + 0.4 .Contrast = .Contrast + 0.4 End With Next End With Application.ScreenUpdating = True End Sub For Mac macro installation & usage instructions, see: https://wordmvp.com/Mac/InstallMacro.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thank you for your reply.
I have another two questions: 1- Is there any way to resize all the images in the word file? For example, resize to 6" by 6". 2- Is there any way to crop all the images in the word file? For example, crop to 6" by 6". Thanks again. |
#4
|
||||
|
||||
Yes to both, but you wouldn't crop a pic you've already resized to the required dimensions.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Thanks. I understand that. There were two different questions and independent of each other.
Anyways, could you please advise how to do the crop to the specific size? Thanks again. |
#6
|
||||
|
||||
You would have to be more specific - as in do you want to crop from the left, right, top or bottom?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Quote:
1- crop 10mm from left. 2- crop 20mm from right. 3- crop 30mm from top. 4- crop 40mm from down. |
#8
|
||||
|
||||
That's as simple as:
Code:
Sub Demo() Application.ScreenUpdating = False Dim i As Long With ActiveDocument For i = 1 To .Shapes.Count With .Shapes(i).PictureFormat .CropTop = CentimetersToPoints(3) .CropBottom = CentimetersToPoints(4) .CropLeft = CentimetersToPoints(1) .CropRight = CentimetersToPoints(2) End With Next For i = 1 To .InlineShapes.Count With .InlineShapes(i).PictureFormat .CropTop = CentimetersToPoints(3) .CropBottom = CentimetersToPoints(4) .CropLeft = CentimetersToPoints(1) .CropRight = CentimetersToPoints(2) End With Next End With Application.ScreenUpdating = True End Sub Note: Cropping is calculated relative to the original size of the picture, not relative to whatever it may have been re-scaled to. If you've re-scaled the picture, you'll need to divide the crop factor by the rescale percentage - which could be different for the horizontal and vertical axes.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
The code works, however, I am not sure why it is not applied to the whole document. I have hundreds of images, however, this code only crops the first twenty, thirty images. The word file is two column, however, I made sure that there is no section break, or anything similar.
Any idea why this is happening? |
#10
|
||||
|
||||
As coded, the macro will process all wrapped and inline shapes in the document. There is nothing in the code that would limit it to less than that. Do bear in mind that, if the images' natural size is very large, the amount cropped of that might be minimal at the size they've been scaled to in the document.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Quote:
For example, two images have similar size in word file (145*160 mm), however, when I save them as image, their properties are: Image 1: Dimensions: 1280*1167 (pixels) vertical/horizontal: 144 (dpi) Image 2: Dimensions: 1280*1167 (pixels) vertical/horizontal: 96 (dpi) and after running the code, the image size in the word file would be: Image 1: 146*103 Image 2: 145*122 I checked and noticed that the images are either 144dpi or 96dpi. I am wondering if there is any way to separately crop the images, according to their dpi. For example, crop the 144 dpi images by 4 mm and crop the 96 dpi images by 3 mm. Thanks again for your time. |
#12
|
||||
|
||||
Without a lot of work, Word can't read the ppi of an image embedded in a document and, in any event, many don't store that figure, with the result that 72ppi is assumed. Furthermore, I'd have thought any cropping related to either: the size the images are displayed at in Word, or the original size (regardless of ppi). Either is easily achieved; relating the crop to the ppi is not.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Thanks. I managed to sort the images by the dpi and do the crop accordingly. So, that issue is solved.
In the following code which you provided, the brightness and contrast are modified. Could you please advise how to change the color to B&W (I assume this is equal to Saturation = 0%)? Thanks again. Quote:
|
#14
|
||||
|
||||
As per my advice in post #8, you should spend a little time learning what methods are available. In this case, you might try:
.ColorType = msoPictureGrayscale
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
formatting, multiple, picture |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word file with a lot of pictures. Picture size small, File size HUGE | Blackcloud_9 | Drawing and Graphics | 1 | 04-10-2018 06:04 AM |
Make a macro apply only on selected pictures | Mattia | Word VBA | 2 | 11-10-2017 12:52 AM |
Macro to apply artistic effect to selected picture in Microsoft Word 2010. | staicumihai | Word VBA | 2 | 11-24-2016 01:41 AM |
VBA Word Table - Select More than 1 Column at a time - Apply Formatting | jc491 | Word VBA | 12 | 09-24-2015 06:03 AM |
how do i apply any change to all pictures in one document | greenil | Word | 0 | 06-18-2013 12:56 AM |