none
Convert picture imported to Word document with VBA RRS feed

  • Question

  • I've Word documents that contain acronyms and a macro that searches the document for them so that they can be identified for an acronym table. So far, I can search a document's text and tables but not the pictures with the macro. I've found that if I manually select the picture, right click and select group->ungroup, I get a MsgBox with the message "This is an imported picture, not a group. Do you want to convert it to a Microsoft Office drawing object?" Selecting the yes button converts it into many Shapes objects that are then searchable.

    I've determined that the picture (object) type prior to conversion is msoPicture and that it gets converted to an msoCanvas object with many Shape objects on it.

    I've built a macro that can loop through various Canvas objects and then the Shape objects to find the acronyms. Unfortunately, I haven't been able to find a way to convert the image/object from msoPicture to msoCanvas in VBA. Does anyone know how to do this? Thanks.

    Thursday, April 2, 2015 5:08 PM

Answers

All replies

  • Hi,

    As far as I know, we can’t convert a picture to canvas through VBA.

    For that process through the UI, I think it add the canvas first, then add the picture to that canvas.

    For your requirement, you could add the canvas first, then add the picture to tat canvas.

     

    Sub NewCanvasPicture()
        Dim shpCanvas As Shape
    
        'Add a drawing canvas to the active document
        Set shpCanvas = ActiveDocument.Shapes _
            .AddCanvas(Left:=100, Top:=75, _
            Width:=200, Height:=300)
    
        'Add a graphic to the drawing canvas
        shpCanvas.CanvasItems.AddPicture _
            FileName:="C:\Program Files\Microsoft Office\" & _
                "Office\Bitmaps\Styles\stone.bmp", _
            LinkToFile:=False, SaveWithDocument:=True
    End Sub
    

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 3, 2015 7:32 AM
    Moderator
  • Starain,

      Thanks, but that doesn't work ... all it does is put a non-text searchable picture on the canvas.

      As far as what MS Word is doing, I think you are right. It doesn't change the Type because it's only a read only property of the Shape object. I thing that it creates a canvas, takes the picture and creates a bunch of Shape objects from that picture, deletes the old picture and pastes the canvas with all of its Shapes into the document.

    So I gues my question is, how do I access that functionality through VBA? What app or macro or set of macros does MS word have in its native environment that takes a document image and creates a Microsoft Drawing object? Thanks.

    Jim

    p.s. I've tried their OCR via OneNote and that doesn't work and tried listing all CommandBarName:ControlCaption in an effort to find this function but couldn't find it.

    Friday, April 3, 2015 7:20 PM
  • Hi Jim,

    I can’t ungroup the image. (The ungroup button is disabled if I select the image), please provide the detail steps that you did.

    Do you try to use Shape.Ungroup method?

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 7, 2015 2:41 AM
    Moderator
  • Starain, The Shape.Ungroup method does not work on Shape objects of Type msoPicture. Therefore my reason to try and find out how MS Word does the conversion. Here's a simple way to get to where I'm at (I'd send this as a word file with screen snips but this medium doesn't allow it): In a new MS PowerPoint (Professional Plus 2010) presentation, create a text box with text in it. Select & copy the box. In a new MS Word (same version) document, from the "Home" ribbon, select Paste->Paste Special. A pop-up will appear. select "Picture (enhanced metafile)". Object will be pasted onto the Word document. Then right click and select Group->Ungroup and the MsgBox previously mentioned will appear. This only works for pictures imported as enhanced metafiles. Thanks. Jim
    Tuesday, April 7, 2015 2:08 PM
  • There is no method available in Word object model to achieve the same.

    -Ajay

    Wednesday, April 22, 2015 7:01 PM
  • Ajay,

      So, what you're saying is that the VBA Word object model does not support this for non-Microsoft developers? Does this mean that Microsoft reserves some object models for their developer use only? I can believe this but it leaves me scratching my head as to why they would do this. Thanks for your reply too.

    Jim

    Monday, April 27, 2015 5:51 PM
  • Hello Jim,

    What I mean is we can’t convert a picture to canvas through VBA. There is no such method exposed which can be used to convert a picture to canvas.

    -Ajay

    Wednesday, April 29, 2015 1:28 PM
  • Ajay,

      Let me repeat what I think you said ... MS Word has an app to do this but it cannot be accessed via VBA. Correct? Thanks again for your patience.

    Jim

    Wednesday, April 29, 2015 6:06 PM
  • That's correct.

    -Ajay

    • Proposed as answer by Ajay Bandooni Monday, May 4, 2015 2:01 PM
    • Marked as answer by JimSchuler Wednesday, May 27, 2015 6:30 PM
    Monday, May 4, 2015 2:01 PM