Preserve Format on Break Link with Table using VBA

G

gkbrenne

I have an document that contains links to an Excel spreadsheet. These links
need to be updateable while the document is being editing and the spreadsheet
data may be changing.

The last step in the process is to create the final document, which would
break the links to the Excel spreadsheet.

I've tried using the following:

Dim alink As Field, linkcode As Range

For Each alink In ActiveDocument.Fields
With alink
If .Type = wdFieldLink Then
.LinkFormat.BreakLink
End If
End With
Next alink

Which breaks the link, but loses the format.

However, if I do it manually I can keep the formatting (Office button >
Prepare > Edit Links to file, check "Preserve Formatting after update", then
click [Break Link]).

Any ideas on how to do this using VBA?
 
D

Doug Robbins - Word MVP

Try:

Dim alink As Field
For Each alink In ActiveDocument.Fields
With alink
If .Type = wdFieldLink Then
alink.Unlink
End If
End With
Next alink



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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