can't capture Edit>Links... in word macro

M

mark mcfarlane

I am trying to create a macro that will break all existing OLE links in a MS Word 2002 document

The master document containes a series of OLE links to text (paragraphs) in other documents. I want to break the links in the master doc so it is only static text. When I record amacro - all document oiperations are captured in teh macro except the Edit>Links... dialog is not captured

I have tried using the following code with no success (perhaps shapes are not word documents?

Dim shapeLoop As Shap
For Each shapeLoop In ActiveDocument.Shape
With shapeLoo
If .Type = msoLinkedOLEObject The
.LinkFormat.Updat
.LinkFormat.BreakLin
End I
End Wit
Next shapeLoo

Any ideas on how to craete this generic macro

Thanks

Mark McFarlane
 
P

Peter Hewett

Hi Mark

Even though you're referring to a Master document I'm taking from what else
you say that it not a real Master/Subdocument(s) were dealing with?

If the files were inserted using Insert/File menu option, then INCLUDETEXT
fields are inserted. If this is the case then you can unlink them using
this code:

Sub UnlinkTextFields()
Dim rngStory As Word.Range
Dim lngIndex As Long

' Iterate through all story types
For Each rngStory In ActiveDocument.StoryRanges

Do Until rngStory Is Nothing

' Do this backwards as we are using the fields
' index and deleteing fields from the same collection at
' the same time
For lngIndex = rngStory.Fields.Count To 1 Step -1
With rngStory.Fields(lngIndex)
If .Type = wdFieldIncludeText Then
.Unlink
End If
End With
Next

' There may be linked stories so make sure we get them as well
Set rngStory = rngStory.NextStoryRange
Loop
Next
End Sub

You can check on the type of field by toggling field code on by selecting
the field and pressing Shift+F9.

If I've missed the mark please explain how subdocuments were inserted.

HTH + Cheers - Peter
 
M

mark mcfarlane

Peter,

Thanks so much for your help, you got me pointed in the right direction. Actually, I was not pasting links the way you specified, instead the links were made by copying a PARAGRAPH of text from the clipboard from one document, and then doing an Edit>Paste Special to create the link in the receiving document. Your code almost worked, I just had to change the enumeration in the .Type comparison to wdFieldLink instead of wdFieldIncludeText

Here's two different subs that solved my problem

Sub UnlinkTextFields(
Dim rngStory As Word.Rang
Dim lngIndex As Lon

' Iterate through all story type
For Each rngStory In ActiveDocument.StoryRange

Do Until rngStory Is Nothin

' Do this backwards as we are using the field
' index and deleteing fields from the same collection a
' the same tim
For lngIndex = rngStory.Fields.Count To 1 Step -
With rngStory.Fields(lngIndex
If .Type = wdFieldLink The
.Unlin
End I
End Wit
Nex

' There may be linked stories so make sure we get them as wel
Set rngStory = rngStory.NextStoryRang
Loo
Nex
End Su

----------------------------
Public Sub unlinkall(

With ActiveDocument.Sections(1).Range.Field
.Updat
.Unlin
End Wit

End Su
 
P

Peter Hewett

Hi Mark

I'm pleased you found your answer. The thing to be wary of with your
Unlinkall procedure is that it will unlink ALL fields in Section 1 of the
BodyTextStory of your document. But Unlink actually removes the field and
just leaves the fields value.

Cheers - Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top