unlock citation field in Word 2007

P

p0

Hello,

I'm having a Word document containing several citation fields. I want
to remove all of those through VBA code:

Public Function DeleteCitations()
Dim fld As Field

For Each fld In Application.ActiveDocument.Fields
If fld.Type = wdFieldCitation Then
fld.Select
Selection.Delete
End If
Next
End Function

The Delete command is not working as for some reason the field is
locked. However, querying the 'Locked' property of the field shows me
that it is set to 'False'.

I noticed that when I add the citation through 'QuickParts' -> 'Field'
rather than through 'References' -> 'Insert citation', the field is
not locked and the Delete command can be executed without problem. So
it looks as if some special type of locking is done.

My current workaround is to do a Selection.Cut which solves the
problem put pollutes the clipboard.

Any idea on how to get rid of the strange lock? Or alternatively, is
there a way to store the current state of the clipboard, do the Cut
commands and then restore the clipboard?

Yves
 
D

Doug Robbins - Word MVP

Try using:

Dim afield As Field
For Each afield In ActiveDocument.Fields
If afield.Type = wdFieldCitation Then
afield.Delete
End If
Next afield


--
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
 
P

p0

Doesn't work. I get a "Method 'Delete' of object 'Field' failed"
error. The error is caused by the special lock hold on the citation
field.

On a side note, I need the "afield.Select" method before doing
"afield.Cut" or "afield.Delete" as the removed field otherwise does
not get placed in the undo buffer.

Regards,

Yves
 
P

p0

A little addition to the problem. The following code works perfectly
and has no problems with the "locks"

Dim fld As Field

For Each fld In Application.ActiveDocument.Fields
If fld.Type = wdFieldCitation Then
fld.Select
Selection.Start = Selection.Start - 1
Selection.End = Selection.End + 1
Selection.Delete
End If
Next


It seems that fld.Select only selects the result of the field (at
least in case of citations), which is locked and can not be deleted
rather than the entire field (that is including the field codes). By
extending the selection with one unit (char) on both sides, the field
codes seem to be included as well and a delete operation can be
performed.

I tried a few variations on the topic but it seems I have to extend
both the start and end position of the selection by at least 1. Only
changing the start or the end value is not enough.

Although this is still a dirty solution, it is at least something I
can work with until someone can solve this locking mystery.

Yves
 

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