Email this Page Log Support Call Send Feedback Print

Previous Topic

Next Topic

Book Contents

Book Index

AfterPublish Macro to Embed Linked Images in Document

By default, when publishing Word documents, all graphics are included in the same folder and linked to by the word document. This enables very large Word documents to be created with little trouble.

If moving the published Word doc, you need to either:

  1. include the files,
  2. convert the doc to PDF, or
  3. save the graphics in the document

The problem with (c), is that unless you follow specific steps, you lose any scaling applied to the graphics – and if you have graphics scaled at various sizes (let's say some at 50%, some at 60%, some 75%, and so on), it is no quick task to go and reset them. It's also an extra step that many of you don't want to have to take.

The following AfterPublish macro can be added to your Word Publishing template to automatically save the graphics in the document, and ensure the scaling is kept intact.

 
Sub LinkShapesAndFields()
 
    ' Embeds linked graphics into document so it
    ' can be moved without breaking links to images
 
    ' Runs through all Shapes, Fields and InlineShapes
    ' and calls the LinkFormat.BreakLink
    ' Written 20-June-2003 Derek Tomes - Author-it
    ' Modified 20-January-2004 DT - ActiveDocument.UndoClear added
 
    Dim objShape As Shape
    Dim objField As Field
    Dim objInlineShape As InlineShape
    Dim objSelection As Selection
 
    PrintPreview = True
    ActiveWindow.Selection.MoveEnd wdStory
    PrintPreview = False
    ActiveDocument.ActiveWindow.View.Type = wdNormalView
 
    For Each objShape In ActiveDocument.Shapes
      If Not objShape.LinkFormat Is Nothing Then
        objShape.LinkFormat.BreakLink
        ActiveDocument.UndoClear
      End If
    Next
    For Each objField In ActiveDocument.Fields
      If Not objField.LinkFormat Is Nothing Then
        objField.LinkFormat.BreakLink
        ActiveDocument.UndoClear
      End If
    Next
    For Each objInlineShape In ActiveDocument.InlineShapes
      If Not objInlineShape.LinkFormat Is Nothing Then
        objInlineShape.LinkFormat.BreakLink
        ActiveDocument.UndoClear
      End If
    Next
End Sub

Top of Page Email this Page Log Support Call Send Feedback Print