PDA

View Full Version : How to change original image sizes in Word



menander
03-01-2017, 03:59 AM
Hi,

I have a macro that will change the sizes of all my images in a document and it works great, but my problem is this...
When you insert an image into Word and then change its shape, the word document then stores two versions of that image. The original image size and your new sized image version displayed on screen. What I want to do is find a macro that will change the original size of the image that is imported into Word, not just the second version of the image.

I have some documents that have hundreds of images in them and I want to convert them into epubs. But when I do this the software creates the ePub with the original large image sizes that were first inserted into the Word document - not the second small version sizes that I have used my macro to create and that show on screen. I have tried compressing all images, but it doesn't work on all of them for some reason - only 90% or so are resized.

Is it possible to use VBA to actually change the original image size of the first version of an image inserted to a specific height, while retaining the aspect ratio? Please note: I can already change all the images in the document, but it is not changing the original image size stored by Word and later used in my epubs.

Thanks all for your help!

gmaxey
03-01-2017, 05:56 AM
So where is your macro?

menander
03-01-2017, 08:37 AM
So where is your macro?

Here it is, thanks:

DesiredHeight = InputBox("Enter desired height for images:", , 400)
For Each ishape In ActiveDocument.InlineShapes
With ishape
ImageWidth = .Width
ImageHeight = .Height
NewHeight = DesiredHeight
NewWidth = Round(NewHeight * ImageWidth / ImageHeight)
.Height = NewHeight
.Width = NewWidth
End With
Next

gmaxey
03-01-2017, 10:19 AM
I created a new document and inserted two picture files from my computer. Each picture took up about 2/3 of a page. I used your macro to resize the pictures to Height = 200. I then saved the document, added a zip extension, unzipped it and looked in the Word\Media folder. There was two file image1 and image2. I copied and pasted both to the desktop and then zipped the document back up, opened it and inserted the image1 and image2 files. Both were inserted as then new size as expected.

Can you attach small before (doc file) and after (doc file) that illustrates your issue?

menander
03-01-2017, 10:42 AM
I created a new document and inserted two picture files from my computer. Each picture took up about 2/3 of a page. I used your macro to resize the pictures to Height = 200. I then saved the document, added a zip extension, unzipped it and looked in the Word\Media folder. There was two file image1 and image2. I copied and pasted both to the desktop and then zipped the document back up, opened it and inserted the image1 and image2 files. Both were inserted as then new size as expected.

Can you attach small before (doc file) and after (doc file) that illustrates your issue?

If you save your Word file as a html document and then close it, look inside the folder with the images. You will see two different versions of each image. The first large size version and the second smaller and less quality size created by resizing in Word. What I want to do is to tell word to forget the first image version and only store the new sized image version.

gmaxey
03-01-2017, 12:14 PM
That doesn't happen here. Here I get just the two smaller files. I don't know anything about html processes though so probably can't help.

macropod
03-02-2017, 12:39 AM
Cross-posted at: http://www.msofficeforums.com/word-vba/34542-how-change-original-image-sizes-word.html
Please read our policy on Cross-Posting in item 3 of the board rules: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3

menander
03-03-2017, 02:44 AM
That doesn't happen here. Here I get just the two smaller files. I don't know anything about html processes though so probably can't help.

Thanks for your help. What I'm trying to say is, Word doesn't remove the original file information of the image you insert. It stores two versions of the image. If you save the file as an html document and then look in the folder of that html document you will see two versions of each image (if the image has been resized at all). There must be a way to code vba to make it delete the original large version of the image and only retain the smaller file info. I've tried changing the inline images to shapes etc, but still can't work out a way to do it.

Any ideas? Thanks

gmaxey
03-03-2017, 07:08 AM
Ok, I see what you are saying now. I started with a new document. Inserted a picture and resized it then saved the file with .html format. When I looked in the file folder, I saw the two files.

However, if I first save the file with a .docx or .docm format then save it as .html, I only see the one smaller file in the file folder.

As I said, I don't know anything about html, so can't help.