1

Hello everyone I have a word document It has 300 pages and every single page having a chart and text when i make place or import to this document into InDesign These charts do not appear or place in the template! is there way or macro to convert all of the charts into images Greetings to all

I found this macro its make copy of any charts but this copy it's very small pictures

Sub EmbedAllCharts()
    Dim ILS As InlineShape
    Dim Shp As Shape

    For Each ILS In ActiveDocument.InlineShapes
        If ILS.Type = wdInlineShapeChart Then
            ILS.Chart.Export Environ$("temp") & "\chart" & ".png", "PNG"
            ILS.Select
            Selection.InlineShapes.AddPicture FileName:=Environ$("temp") & "\chart" & ".png", _
                LinkToFile:=False, SaveWithDocument:=True
        End If
    Next ILS

    For Each Shp In ActiveDocument.Shapes
        If Shp.Type = msoChart Then
            Shp.Chart.Export Environ$("temp") & "\chart" & ".png", "PNG"
            Shp.Select
            Selection.InlineShapes.AddPicture FileName:=Environ$("temp") & "\chart" & ".png", _
                LinkToFile:=False, SaveWithDocument:=True
            Shp.Delete
        End If
    Next Shp
End Sub

enter image description here
enter image description here

ways or macro to convert charts into images

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
Hassan
  • 13
  • 2
  • 1
    Have you tried converting the Word document into a PDF and then importing the PDF into InDesign? – joeschwa May 29 '23 at 17:05
  • 1
    I would try to save the document as an RTF and then import it in InDesign. RTF is an legacy format it handles the images in a more simple way. And by the way, DOCX is actually an archive with files and folders, it contain all the images inside one of the inner folders (..word/media/). You can unpack it, get all the images manually. – Yuri Khristich May 30 '23 at 08:32
  • @joeschwa yes I'm converting word into pdf but I cant edit the text above a charts! – Hassan May 30 '23 at 17:23
  • @YuriKhristich I tried before make this question but when I make my document.RTF the charts also not import into indesign – Hassan May 30 '23 at 17:25
  • I just tried to save my test document with charts as an old Word 97-2004 .DOC (not a .DOCX) and placed the DOC into InDesign as usual, and it does the trick. All the charts were successfully imported as plain PNG pictures. – Yuri Khristich May 31 '23 at 21:19
  • 1
    @YuriKhristich thank you so much for your interest in the subject The method you mentioned is very good and worked for me. I am grateful to you Good luck – Hassan Jun 01 '23 at 07:59
  • Can you give a sample to me to try and test? – Oscar Sun Jun 02 '23 at 05:59
  • did this help? [Word vba how to save picture from image object to file?](https://stackoverflow.com/questions/31922261/word-vba-how-to-save-picture-from-image-object-to-file) – Oscar Sun Jun 02 '23 at 06:49
  • @OscarSun in my case I just insert a charts inside of MS word and my question is how import this charts into InDesign the macro didn't help me. – Hassan Jun 03 '23 at 09:42

1 Answers1

1

I don't have InDesign now, so I can't test that part, but I've known that before using the Export method, you can zoom in on the Chart and then export it to get a larger, clearer image. Something like this:

Sub EportAllChartsInLargeSize()
    Dim ILS As InlineShape
    Dim Shp As Shape
    
    Dim i As Long, ur As Word.UndoRecord

    Set ur = Word.Application.UndoRecord
    ur.StartCustomRecord "EportAllChartsInLargeSize"
    
    For Each ILS In ActiveDocument.InlineShapes
        If ILS.Type = wdInlineShapeChart Then
        
            Rem Before using the Export method, you can zoom in on the Chart and then export it to get a larger, clearer image.
            ZoomInlineShape ILS, 2
            
            ILS.Chart.Export Environ$("temp") & "\chart" & i & ".png", "PNG"
            
            'ILS.Range.Document.Undo 'restore the size
            
'            ILS.Select
'            Selection.InlineShapes.AddPicture FileName:=Environ$("temp") & "\chart" & ".png", _
                LinkToFile:=False, SaveWithDocument:=True
                
            i = i + 1
        End If
    Next ILS

    For Each Shp In ActiveDocument.Shapes
        If Shp.Type = msoChart Then
            Rem Before using the Export method, you can zoom in on the Chart and then export it to get a larger, clearer image.
            ZoomShape Shp, 2
            
            Shp.Chart.Export Environ$("temp") & "\chart" & i & ".png", "PNG"
            
            'Shp.Anchor.Document.Undo 'restore the size
            
'            Shp.Select
'            Selection.InlineShapes.AddPicture FileName:=Environ$("temp") & "\chart" & ".png", _
'                LinkToFile:=False, SaveWithDocument:=True
'            Shp.Delete

            i = i + 1
        End If
    Next Shp
    
    ur.EndCustomRecord
    ActiveDocument.Undo 'restore the size
    
End Sub
Sub ZoomInlineShape(ByRef ILS As InlineShape, percentage As Single)
    With ILS
        .LockAspectRatio = msoTrue
        .Width = .Width * percentage
'        .Height = .Height * percentage
    End With
End Sub
Sub ZoomShape(ByRef Shp As Shape, percentage As Single)
    With Shp
        .LockAspectRatio = msoTrue
        .Width = .Width * percentage
'        .Height = .Height * percentage
    End With
End Sub
Sub ExportChart()
    Dim ILS As InlineShape
    Dim objChart As Chart 'Object
    Dim strFilePath As String
    Dim strFileName As String
    Dim objInDesign As Object 'InDesign.Application
    Dim objDoc As Object 'InDesign.Document
    
    Rem Before using the Export method, you can zoom in on the Chart and then export it to get a larger, clearer image.
    Set ILS = ActiveDocument.InlineShapes(2) ' This is just for my test, you can adjust to yours
    ZoomInlineShape ILS, 2
    
    ' Get the active chart object in Word
    Set objChart = ActiveDocument.InlineShapes(2).Chart

    ' Get the file path and name for the exported chart
    strFilePath = VBA.Environ("userprofile") + "\Documents\" '"C:\\Temp\\"
    strFileName = "chartTest.png"

    
    ' Export the chart to the specified file location
    objChart.Export FileName:=strFilePath & strFileName, FilterName:="PNG"

    ILS.Range.Document.Undo 'restore the size
    
    Stop
    
    Rem This code below is the answer of YouChat and I don't have InDesign so I can't test. Sorry. Maybe you can try
    ' Open the InDesign application
    Set objInDesign = CreateObject("InDesign.Application")

    ' Open the InDesign document where you want to import the chart
    Set objDoc = objInDesign.Open("C:\\Users\\UserName\\Documents\\MyDocument.indd")

    ' Insert the exported chart into the InDesign document
    objDoc.Pages(1).Place strFilePath & strFileName

    ' Save and close the InDesign document
    objDoc.Save
    objDoc.Close

    ' Clean up
    Set objChart = Nothing
    Set objInDesign = Nothing
    Set objDoc = Nothing
End Sub
Oscar Sun
  • 1,427
  • 2
  • 8
  • 13