Deleted Date Field Reappears Upon Reopen of Doc

R

Raul

I'm using the following code to remove the date field in a table in a header.
It was working on a batch of documents and then appeared to work on a second
batch of documents. The date field was replaced with "1" as dersired and the
document was saved. However when the document was opened the date field was
back.

One difference in the two batches of documents is I attached a new template
to documents in the second batch (with the issue).

Regardless, I still need the date field deleted permanently.

Can someone please help?

With ActiveDocument.StoryRanges(wdFirstPageHeaderStory).Tables(1)
' For c = 1 To .Columns.Count
c = .Columns.Count
For r = 2 To .Rows.Count
Set DateFieldRng = .Cell(r, c).Range
If DateFieldRng.Fields.Count > 1 Then
If DateFieldRng.Fields(1).Type = 31 Then
' DateFieldRng.Fields(1).Select
' Selection.Fields(1).Delete
DateFieldRng.Select
Selection.Delete
DateFieldRng.Text = 1
Exit For
End If
End If
Next r
' Next c
End With

Thanks in advance,
Raul
 
D

Doug Robbins - Word MVP

Maybe you need to change

If DateFieldRng.Fields.Count > 1 Then

to

If DateFieldRng.Fields.Count > 0 Then

The way it is, if there is only one field in the cell, then the rest of the
code within that If...End If construct would not be executed.


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

Raul

Doug,
Thanks a bunch. I changed:

If DateFieldRng.Fields.Count > 1 to
If DateFieldRng.Fields.Count >= 1

And

If DateFieldRng.Fields(1).Type = 31 to
If DateFieldRng.Fields(1).Type = 31 Or If DateFieldRng.Fields(1).Type = 32

All is well with the world now.

Thanks again,
Raul
 

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