How to Lock links (programatically) without incurring an update

T

Taylor

I have found several past posts on locking links in VBA. (Cribbed code
is included at the footer of the message.)

I would like to discover the programmatic equivalent of the manual
method of locking links: Edit--->Links (Opens dialogue); Select all
links, check 'Locked' box; click OK.

Problems with my current VBA method:
a) the original linked source file needs to be present for my code to
even work. (Not the case with locking links manually.)

Running code sans source file returns: "Run-time error '6083' Objects
in this document contain links to files that cannot be found. The
linked information will not be updated," leading to the next issue...

b) With the code, Word first updates the links before setting them to
Locked. Not desirable, timewise (manual locks instantaneously, vba
takes 1.5 min+) & the updates are likely irrelevant to the current
doc.

c) The other thing that is so darn snazzy about the manual method is
that it doesn't care if it is a field, shape, inline shape; it just
locks the bugger. In code, I need separate processes to deal with each
type of link (Probably unavoidable).

Any help is greatly appreciated. Thanks!


Taylor


P.S. I had high hopes of running the macro recorder during the above
manual process; alas, it registers nothing (results in blank macro
code).

Here's the code:

Dim i As Long
For i = 1 To ActiveDocument.Shapes.Count
If Not ActiveDocument.Shapes(i).LinkFormat Is Nothing Then
If Not ActiveDocument.Shapes(i).LinkFormat.Locked Then
ActiveDocument.Shapes(i).LinkFormat.Locked = True
End If
End If
Next i
 
D

Doug Robbins

Use something like:

Dim alink As Field
For Each alink In ActiveDocument.Fields
If alink.Type = wdFieldLink Then 'test of other types of fields too if
necessary
alink.Locked = True
End If
Next alink


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
T

Taylor

Doug,

My apologies; I did not mean to take your help for granted. Something
rather dire has come up at work, and I have not had a chance to try
out your suggestion. I will let you know how it works as soon as I
have a couple of free hours to tinker.

Thanks for your help so far,

Taylor
 

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