I am trying to convert shapes embedded in a Word document into image files so that I can display them in a UserForm. My current approach involves using Microsoft Publisher to save the shapes as image files. While this method works, it takes a significant amount of time. Here is the code I am using:

Sub ShowImg()

    Dim ImgShape As Shape
    Dim ImgPath As String
    Dim tbl As Table
    Dim TempFolderPath As String
    Dim OriginalWidth As Single
    Dim OriginalHeight As Single
    Dim P As Object

    Set tbl = ActiveDocument.Tables(1)
    TempFolderPath = ActiveDocument.Path & Application.PathSeparator
    ImgPath = TempFolderPath & "temp_img_2.png"
    Set ImgShape = ActiveDocument.Shapes(2)
        With ImgShape
            OriginalWidth = .Width
            OriginalHeight = .Height
        End With
    Set P = CreateObject("Publisher.Document")
    With P.Pages(1).Shapes.Paste(1)
        .LockAspectRatio = False
        .Width = OriginalWidth
        .Height = OriginalHeight
        .SaveAsPicture ImgPath
    End With
    Set P = Nothing
    'Kill ImgPath

End Sub

Is there a more efficient way to convert Word shapes into images? Any alternative approaches or improvements to reduce the execution time would be greatly appreciated.

New contributor
VBAbyMBA is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.