Consulting

Results 1 to 9 of 9

Thread: How to change original image sizes in Word

  1. #1
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    4
    Location

    How to change original image sizes in Word

    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!

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    So where is your macro?
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    4
    Location
    Quote Originally Posted by gmaxey View Post
    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

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    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?
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    4
    Location
    Quote Originally Posted by gmaxey View Post
    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.

  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    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.
    Greg

    Visit my website: http://gregmaxey.com

  7. #7
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cross-posted at: http://www.msofficeforums.com/word-v...izes-word.html
    Please read our policy on Cross-Posting in item 3 of the board rules: http://www.vbaexpress.com/forum/faq...._new_faq_item3
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  8. #8
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    4
    Location
    Quote Originally Posted by gmaxey View Post
    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

  9. #9
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    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.
    Greg

    Visit my website: http://gregmaxey.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •