wdFieldType values

R

Ron John

Where can I find an exhaustive explanation to the meaning
of wdFieldType values? As it usually happens with VBA
help, a complete list of values is presented
(wdFieldAddIn, wdFieldAdvance...), but there's no way to
know how those constants work.
I've searched in WordBasic help too, trying to find some
kind of analogy, but that didn't help me at all.

Thanks.
 
J

Jay Freedman

Hi Ron,

When you peel off the wdField prefix, what's left corresponds to the keyword
that starts the field code of the field you'll get when you use Fields.Add.

Ask the regular Word help file for "Field code <type>" for that <type> --
for example, ask about "Field code AddIn" or "Field code Advance". You'll get
a list of the other information that can be included in that field code, such
as a bookmark name, a file name, or various switches.
 
J

Jezebel

As a general answer, of course, it's quite right. But AddIn fields are not
documented in Help.
 
R

Ron John

Thanks for the info, I have sorted out that bit already.
Now I have another question: how can I remove all the auto fields in the
document.
The code below doesn't work in all occasions. In some instances, after
running that code, the document still contains some auto fields. Most of the
time they are at the end of the document, usually in headers and footers.
Any ideas why that happens?

Set objWord = New Word.Application
Set objDoc = objWord.Documents.Open("C:\1.doc", False, True, , "")
With objDoc
For i = 1 To .Fields.Count
.Fields(i).Delete
Next i
.SaveAs "C:\1.txt", wdFormatText
.Close wdDoNotSaveChanges
End With
 
J

Jezebel

The document.Fields() collection includes only the fields in the body of the
document. To get all fields, wherever they occur, you need to iterate all
the SotryRanges separately --

Dim pRange as Word.Range
For each pRange in objDoc.StoryRanges
Do
Do until pRange.Fields.Count = 0
pRange.Fields(1).Delete
Loop
set pRange = pRange.Next
Loop until pRange is nothing
Next
 
R

Ron John

Excellent! That's exactly what I was looking for.
My mistake was to assume that document.fields() returns all the fields in
the document...
Thanks a lot for your help.
 
R

Ron John

Hi Jezebel,
I've got a document that i am having troubles deleting all auto fields. You
can see this document at http://www.loutom.f2s.com/1.doc
At some point fields.count stays the same no mater how many times you call
fields(1).delete.
Can you please shed some light on why certain fields can not be deleted ?
 
B

Bob S

Hi Jezebel,
I've got a document that i am having troubles deleting all auto fields. You
can see this document at http://www.loutom.f2s.com/1.doc
At some point fields.count stays the same no mater how many times you call
fields(1).delete.
Can you please shed some light on why certain fields can not be deleted ?

Does the document have multiple sections with headers or footers that
have "same as previous" turned off and one of the headers or footers
is empty?

Bob S
 

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