Class LinkFormat (Word VBA)

The class LinkFormat represents the linking characteristics for an OLE object or picture. To use a LinkFormat class variable it first needs to be instantiated, for example


Dim lft as LinkFormat
Set lft = ActiveDocument.Fields(1).LinkFormat

AutoUpdate

True if the specified link is updated automatically when the container file is opened or when the source file is changed.


Dim shapeLoop as Shape 
 
For Each shapeLoop In ActiveDocument.Shapes 
 With shapeLoop 
 If .Type = msoLinkedOLEObject Then 
 If .LinkFormat.AutoUpdate = False Then 
 .LinkFormat.Update 
 End If 
 End If 
 End With 
Next s

Breaks the link between the source file and the specified OLE object, picture, or linked field.

After you use this method, the link result won't be automatically updated if the source file is changed.


Dim shapeLoop As Shape 
 
For Each shapeLoop In ActiveDocument.Shapes 
 With shapeLoop 
 If .Type = msoLinkedOLEObject Then 
 .LinkFormat.Update 
 .LinkFormat.BreakLink 
 End If 
 End With 
Next shapeLoop

Locked

True if a Field, InlineShape, or Shape object is locked to prevent automatic updating.

If you use this property with a Shape object that is a floating linked picture (a picture added with the AddPicture method of the Shapes object), an error occurs.


ActiveDocument.Fields(1).LinkFormat.Locked = True

SavePictureWithDocument

True if the specified picture is saved with the document.

This property works only with shapes and inline shapes that are linked pictures.


Set myPic = ActiveDocument.InlineShapes(1) 
If myPic.Type = wdInlineShapeLinkedPicture Then 
 myPic.LinkFormat.SavePictureWithDocument = True 
End If

SourceFullName

Returns or sets the path and name of the source file for the specified linked OLE object, picture, or field.

Using this property is equivalent to using in sequence the SourcePath, PathSeparator, and SourceName properties.


With ActiveDocument.Shapes(1) 
 If .Type = msoLinkedOLEObject Then 
 With .LinkFormat 
 .SourceFullName = "c:\my documents\myExcel.xls" 
 .AutoUpdate = True 
 End With 
 End If 
End With

SourceName

Returns the name of the source file for the specified linked OLE object, picture, or field.

This property doesn't return the path for the source file.


For Each s In ActiveDocument.Shapes 
 If s.Type = msoLinkedOLEObject Then 
 Msgbox s.LinkFormat.SourcePath & "\" _ 
 & s.LinkFormat.SourceName 
 End If 
Next s

SourcePath

Returns the path of the source file for the specified linked OLE object, picture, or field.

The path doesn't include a trailing character (for example, "C:\MSOffice"). Use the PathSeparator property to add the character that separates folders and drive letters. Use the SourceName property to return the file name without the path and use the SourceFullName property to return the path and file name together.


For Each s In ActiveDocument.Shapes 
 If s.Type = msoLinkedOLEObject Then 
 Msgbox s.LinkFormat.SourcePath & "\" _ 
 & s.LinkFormat.SourceName 
 End If 
Next s

Type

Returns the link type. Here you can find possible values for WdLinkType.


Dim wltType As WdLinkType
wltType = ActiveDocument.Fields(1).LinkFormat.Type

Update

Updates the specified link format.


ActiveDocument.Fields(1).LinkFormat.Update