none
How can I change the bitmap in a Shape and/or InlineShape object? RRS feed

All replies

  • Word is not a graphics editor and Word 2016 provides no additional graphics editing tools.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, January 12, 2018 8:01 PM
  • That's not what I'm asking. I'm just asking if I can change (replace) the bitmap content in a shape. I can change the padding, borders, cropping, etc. But the one thing that can't be changed is the actual bitmap.

    Did they add that in Word 2016?

    thanks - dave


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Friday, January 12, 2018 8:17 PM
  • Word has always had the ability to replace one image with another, regardless of the file format. Simply right-click on it and choose 'Change Picture' - or use 'Change Picture' on the Adjust tab of the Picture Tools contextual ribbon. Word also provides tools for applying artistic effects and colour corrections, including background removal. Anything fancier amounts to editing the image, for which you need a graphics editor.

    Cheers
    Paul Edstein
    [MS MVP - Word]


    • Edited by macropodMVP Friday, January 12, 2018 9:58 PM
    Friday, January 12, 2018 9:50 PM
  • But how do I do it from the COM API setting a property or calling a method in the InlineShape object?

    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Friday, January 12, 2018 10:07 PM
  • Word's API doesn't have anything equivalent to the 'Change Picture' button, nor does there appear to be a commandbar ID you might leverage, so you'd need to use something like:

    Dim Rng As Range
    Set Rng = ActiveDocument.InlineShapes(1).Range
    Rng.InlineShapes.AddPicture "C:\Users\" & Environ("Username") & "\Pictures\MyPic.gif"
    Rng.InlineShapes(2).Delete
    If you have borders, etc., to re-apply based on whatever's applied to the existing inlineshape, you would need to do that between adding the new inlineshape and deleting the existing one.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Proposed as answer by Terry Xu - MSFT Monday, January 15, 2018 5:57 AM
    • Unproposed as answer by DavidThi808 Monday, January 15, 2018 6:06 PM
    Saturday, January 13, 2018 2:03 AM
  • Yes that's what we're presently doing. Occasionally the new image does not show up where the old image was.

    I hope one of these days Microsoft adds that functionality.


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Saturday, January 13, 2018 1:30 PM
  • I've never tried it, but theoretically you should be able to change the graphic content by manipulating the Open XML...?

    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Saturday, January 13, 2018 7:06 PM
    Moderator
  • Set InlineShapes(1).LinkFormat.SourceFullName to the fullname of the picture you want.

    Peter Jamieson


    Sunday, January 14, 2018 7:46 AM
  • Hi Cindy - long time since we last talked :)

    We've tried that approach too, changing the OpenXML at that location. Usually works but sometimes throws an exception.

    thanks - dave


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Monday, January 15, 2018 6:06 PM
  • Yeah, it was good to see your name - takes me back a few years <g>

    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Tuesday, January 16, 2018 4:36 PM
    Moderator
  • That changes the name but not the bitmap contents.

    thanks - dave


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Thursday, August 23, 2018 12:55 PM
  • Yes, my bad - it seems to work in the specific case where you already have a linked picture and therefore a LinkObject, but (a) no good otherwise and (b) might no even always work in that case.

    Personally, if the approaches suggested by Paul & Cindy cannot be made reliable, I doubt if anything can.

    You can pop-up the dialog that Word uses to do it using

    CommandBars.ExecuteMso ("PictureChangeFromFile")


    but then (a) you have to control it. You could might be able to SendKeys("fullpathname{ENTER}"), but that's not reliable, so I think you'd have to have your own code for processing Windows messages. And (b) at the very least you'll probably have to adjust the image dimensions.


    Peter Jamieson

    Thursday, August 23, 2018 3:01 PM
  • I can see no reason why the approach I suggested for an InlineShape object might result in "Occasionally the new image does not show up where the old image was", since the code I proposed can only put the new image exactly where the old one was. As I also noted, though, some additional edits might be required to restore borders, etc., and that would include any appropriate dimensional adjustments. Nevertheless, the new image would be in the same location as the original.

    For wrapped shapes (which the OP excluded, by specifying 'the InlineShape object'), though, additional code would be required to catch & restore the original's position.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, August 23, 2018 9:58 PM
  • Paul - I agree it should always work. Unfortunately it does not. Over the years we've reported replicable examples to Microsoft of the image being placed in the wrong place, not being placed, etc.

    But the errors remain.


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Friday, August 24, 2018 3:46 PM
  • Perhaps you could upload a document demonstrating the problem to OneDrive and post a link here so the issue can be investigated?

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, August 24, 2018 11:52 PM