Error 4198 wdfieldlink and wdfielddocvariable - breaking & unlinki

J

JAG777

I have a word template which has a number of graphs (wdfieldlinks created by
inserting manual Excel graph links with copy/paste special/link) and
variables taken from a user form (wdfielddocvariable).
I have tried a number of ways to get the newly created word doc to update
the graphs and docvariables, and then break the links - but have reached a
dead-end.
The unlink method, if sent to the fields property of the active document,
appears to stop the update method for wdfieldlinks, but not
wdfielddocvariables - so I end up with a doc that has incorrect graphs - but
correct, updated data. So, I have used the following code after the general
update command in order to break the links / unlink the links by field type:

Activedocument.fields.update

For Each fldElement In .Fields

Select Case fldElement.Type
Case wdFieldLink
fldElement.LinkFormat.BreakLink
Case Else
fldElement.Unlink
End Select

Next

This gives me the error 4198.

I am new to VBA programming and am learning from books (which I'm finding
can be quite vague) so apologies if this is an elementary problem. Any help
would be very gratefully received.

jag777
 
D

Dave Lett

Hi Jag,

I can't reproduce your issue. I can unlink all fields (including Link
fields) using Unlink. I can also unlink the fields using the Unlink and
BreakLink routine that you have.

Error 4198 is a basic Command Failed error message. Can you click a debug
button on this message? If so, what line in the compiler is highlighted?

Dave
 
J

JAG777

Hi Dave,

Thanks for your input.

The line of code that fails is 'fldElement.LinkFormat.BreakLink' in the
select case statement.
I can get the links to unlink or break (depending on type) using template
code to manipulate the active document, but the graphs (link fields) don't
show the new figures. If I don't unlink - they do - probably best if I
explain this a little more...

I have an XL wkb and the word .dot template, which has a user form that
starts with the new document event.
The form takes a series of figures, which are used to do two things:

1 - Update a group of docvariable fields through the new word document
2 - Used to update the dataset of the graph in the XL wbk.

The above works fine - i.e. the XL wkb's state is changed as expected after
running the macro and the docvariable fields are all updated accordingly.

What I am trying to achieve (in code within the template) is the equivelent
of right-clicking on each graph (within the newly created doc ), updating the
link (to reflect the changes made via the word to Excel automation) and break
the links.
If I don't use the unlink method, then I get updated graphs and docvariables
- but still have live links (which although is fit for purpose, is not ideal
and looks messy f the user types on a link). If I do use the unlink method, I
get updated docvariables, but graphs as per the template (i.e. they don't
update to the new dataset which is working in the XL wkb?) - hence, my poor
attempt to either break link or unlink based upon the field type.

Hopefully this makes some sense!

Just to add - if you try to emulate the same issue without the use of a
template (i.e. code it within ThisDocument) it seems to work fine. It's
something to do with the template - I think anyway...?

Regards,

jag777
 

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