George
2004-10-12 04:55:59 UTC
Hi,
I want to differentiate between linked and embedded objects programmatically
using VBA inside a Word Template, so I did the following test where I
inserted the same file twice; once as embedded and another as linked. I
followed the following steps.
First, I added an embedded file as follows:
· Selected "Insert|Object.",
· Selected "Create from File: tab,
· Clicked "Browse" button and browsed to "C:\Temp\ WAV TEST
FILE.wav"
· Clicked "Insert" button" in the browse dialog box
· Left "o Link to file" unchecked
· Left "o Display as icon" unchecked
· Clicked "OK"
The resulting field code was { EMBED Package }
Second, I linked the same file as the following:
· Selected "Insert|Object.",
· Selected "Create from File: tab,
· Clicked "Browse" button and browsed to "C:\Temp\ WAV TEST
FILE.wav"
· Clicked "Insert" button" in the browse dialog box
· Checked "þ Link to file"
· Left "o Display as icon" unchecked
· Clicked "OK"
The resulting field code was { EMBED Package } which shows the object as
embedded not linked. I know they are different internally because if I save
the document, close it, then open it after deleteing the linked file (in
this case "C:\Temp\ WAV TEST FILE.wav"), double clicking on the linked
object won't launch the object while the embedded object will be launched
with a double click.
Moreover, I added some code in VBA and iterated through the InlineShapes
collection to check what is the difference between the 2 inline shapes, but
found there were none; both has the same ProgID and ClassType ("Package"),
and no any other variable in the collection differ or indicate the
linking/embedding difference between the two objects (when I checked inside
watch window of VBA editor). Both have the same type of inlineshape
"wdInlineShapeEmbeddedOLEObject" and not "wdInlineShapeLinkedOLEObject" for
the linked one which is what shoul be logically. The code to iterate though
the inline shapes is as follows.
Private Sub IterateThroughInlineShapes()
Dim ilsCurrent As Word.InlineShape ' current inlineshape
For Each ilsCurrent In ActiveDocument.InlineShapes
DoEvents ' multi-taks
Debug.Print "---------------------------------------------"
If ilsCurrent.Type = wdInlineShapeLinkedOLEObject Then
Debug.Print "InlineShape Type: wdInlineShapeLinkedOLEObject - #"
_
& ilsCurrent.Type
Debug.Print "Class Type: " & ilsCurrent.OLEFormat.ClassType
Debug.Print "ProgID: " & ilsCurrent.OLEFormat.ProgID
ElseIf ilsCurrent.Type = wdInlineShapeEmbeddedOLEObject Then
Debug.Print "InlineShape Type: wdInlineShapeEmbeddedOLEObject -
#" _
& ilsCurrent.Type
Debug.Print "Class Type: " & ilsCurrent.OLEFormat.ClassType
Debug.Print "ProgID: " & ilsCurrent.OLEFormat.ProgID
ElseIf ilsCurrent.Type = wdInlineShapeLinkedOLEObject Then
Debug.Print "InlineShape Type: wdInlineShapeLinkedOLEObject - #"
_
& ilsCurrent.Type
Debug.Print "Class Type: " & ilsCurrent.OLEFormat.ClassType
Debug.Print "ProgID: " & ilsCurrent.OLEFormat.ProgID
ElseIf ilsCurrent.Type = wdInlineShapeLinkedPicture Then
Debug.Print "InlineShape Type: wdInlineShapeLinkedPicture - #" _
& ilsCurrent.Type
ElseIf ilsCurrent.Type = wdInlineShapeEmbeddedOLEObject Then
Debug.Print "InlineShape Type: wdInlineShapeEmbeddedOLEObject -
#" _
& ilsCurrent.Type
Debug.Print "Class Type: " & ilsCurrent.OLEFormat.ClassType
Debug.Print "ProgID: " & ilsCurrent.OLEFormat.ProgID
Else
Debug.Print "InlineShape Type: [else] - #" & ilsCurrent.Type
End If
Next
End Sub
My only question isL: if this is the case, how do I differentiate them and
to get the SourceFullPath for the linked object?
Regards,
George
I want to differentiate between linked and embedded objects programmatically
using VBA inside a Word Template, so I did the following test where I
inserted the same file twice; once as embedded and another as linked. I
followed the following steps.
First, I added an embedded file as follows:
· Selected "Insert|Object.",
· Selected "Create from File: tab,
· Clicked "Browse" button and browsed to "C:\Temp\ WAV TEST
FILE.wav"
· Clicked "Insert" button" in the browse dialog box
· Left "o Link to file" unchecked
· Left "o Display as icon" unchecked
· Clicked "OK"
The resulting field code was { EMBED Package }
Second, I linked the same file as the following:
· Selected "Insert|Object.",
· Selected "Create from File: tab,
· Clicked "Browse" button and browsed to "C:\Temp\ WAV TEST
FILE.wav"
· Clicked "Insert" button" in the browse dialog box
· Checked "þ Link to file"
· Left "o Display as icon" unchecked
· Clicked "OK"
The resulting field code was { EMBED Package } which shows the object as
embedded not linked. I know they are different internally because if I save
the document, close it, then open it after deleteing the linked file (in
this case "C:\Temp\ WAV TEST FILE.wav"), double clicking on the linked
object won't launch the object while the embedded object will be launched
with a double click.
Moreover, I added some code in VBA and iterated through the InlineShapes
collection to check what is the difference between the 2 inline shapes, but
found there were none; both has the same ProgID and ClassType ("Package"),
and no any other variable in the collection differ or indicate the
linking/embedding difference between the two objects (when I checked inside
watch window of VBA editor). Both have the same type of inlineshape
"wdInlineShapeEmbeddedOLEObject" and not "wdInlineShapeLinkedOLEObject" for
the linked one which is what shoul be logically. The code to iterate though
the inline shapes is as follows.
Private Sub IterateThroughInlineShapes()
Dim ilsCurrent As Word.InlineShape ' current inlineshape
For Each ilsCurrent In ActiveDocument.InlineShapes
DoEvents ' multi-taks
Debug.Print "---------------------------------------------"
If ilsCurrent.Type = wdInlineShapeLinkedOLEObject Then
Debug.Print "InlineShape Type: wdInlineShapeLinkedOLEObject - #"
_
& ilsCurrent.Type
Debug.Print "Class Type: " & ilsCurrent.OLEFormat.ClassType
Debug.Print "ProgID: " & ilsCurrent.OLEFormat.ProgID
ElseIf ilsCurrent.Type = wdInlineShapeEmbeddedOLEObject Then
Debug.Print "InlineShape Type: wdInlineShapeEmbeddedOLEObject -
#" _
& ilsCurrent.Type
Debug.Print "Class Type: " & ilsCurrent.OLEFormat.ClassType
Debug.Print "ProgID: " & ilsCurrent.OLEFormat.ProgID
ElseIf ilsCurrent.Type = wdInlineShapeLinkedOLEObject Then
Debug.Print "InlineShape Type: wdInlineShapeLinkedOLEObject - #"
_
& ilsCurrent.Type
Debug.Print "Class Type: " & ilsCurrent.OLEFormat.ClassType
Debug.Print "ProgID: " & ilsCurrent.OLEFormat.ProgID
ElseIf ilsCurrent.Type = wdInlineShapeLinkedPicture Then
Debug.Print "InlineShape Type: wdInlineShapeLinkedPicture - #" _
& ilsCurrent.Type
ElseIf ilsCurrent.Type = wdInlineShapeEmbeddedOLEObject Then
Debug.Print "InlineShape Type: wdInlineShapeEmbeddedOLEObject -
#" _
& ilsCurrent.Type
Debug.Print "Class Type: " & ilsCurrent.OLEFormat.ClassType
Debug.Print "ProgID: " & ilsCurrent.OLEFormat.ProgID
Else
Debug.Print "InlineShape Type: [else] - #" & ilsCurrent.Type
End If
Next
End Sub
My only question isL: if this is the case, how do I differentiate them and
to get the SourceFullPath for the linked object?
Regards,
George