Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Drawing and Graphics

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 07-14-2018, 05:08 AM
si14 si14 is offline Windows Vista Office 2010 32bit
Novice
 
Join Date: Jun 2012
Posts: 12
si14 is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 07-14-2018, 09:54 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,393
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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 PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
For Mac macro installation & usage instructions, see: https://wordmvp.com/Mac/InstallMacro.html
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 07-16-2018, 04:30 AM
si14 si14 is offline Windows Vista Office 2010 32bit
Novice
 
Join Date: Jun 2012
Posts: 12
si14 is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 07-18-2018, 03:10 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,393
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Yes to both, but you wouldn't crop a pic you've already resized to the required dimensions.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 07-21-2018, 03:28 AM
si14 si14 is offline Windows Vista Office 2010 32bit
Novice
 
Join Date: Jun 2012
Posts: 12
si14 is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 07-21-2018, 11:44 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,393
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

You would have to be more specific - as in do you want to crop from the left, right, top or bottom?
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #7  
Old 07-23-2018, 03:15 AM
si14 si14 is offline Windows Vista Office 2010 32bit
Novice
 
Join Date: Jun 2012
Posts: 12
si14 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
You would have to be more specific - as in do you want to crop from the left, right, top or bottom?
Thanks again. I want to crop all images in the doc file as:
1- crop 10mm from left.
2- crop 20mm from right.
3- crop 30mm from top.
4- crop 40mm from down.
Reply With Quote
  #8  
Old 07-23-2018, 06:20 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,393
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
I suggest you spend a little time learning what methods are available to VBA for whatever you're trying to do.

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
[MS MVP - Word]
Reply With Quote
  #9  
Old 07-25-2018, 02:55 AM
si14 si14 is offline Windows Vista Office 2010 32bit
Novice
 
Join Date: Jun 2012
Posts: 12
si14 is on a distinguished road
Default

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?
Reply With Quote
  #10  
Old 07-25-2018, 03:55 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,393
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
  #11  
Old 07-27-2018, 09:58 PM
si14 si14 is offline Windows Vista Office 2010 32bit
Novice
 
Join Date: Jun 2012
Posts: 12
si14 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
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.
Thanks. As you mentioned, it is related to the image properties.
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.
Reply With Quote
  #12  
Old 07-27-2018, 10:36 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,393
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
  #13  
Old 07-28-2018, 02:26 AM
si14 si14 is offline Windows Vista Office 2010 32bit
Novice
 
Join Date: Jun 2012
Posts: 12
si14 is on a distinguished road
Default

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:
Originally Posted by macropod View Post
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 PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
For Mac macro installation & usage instructions, see: https://wordmvp.com/Mac/InstallMacro.html
Reply With Quote
  #14  
Old 07-28-2018, 03:31 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,393
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
Reply

Tags
formatting, multiple, picture

Thread Tools
Display Modes


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


All times are GMT -7. The time now is 10:08 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft