Listing Field Values used in a document

MS WORD

    Next

  • 1. drugs
    i am not on drugs but i need to know what they do to you?
  • 2. Double clicing folders opens search box not folder
    When I double click on a folder icon, the search box opens. I can only open folders by right clicking and selecting open. The open command is the second command when I right click, instead of the first. Using Word 2003 and XP pro
  • 3. was kuwait a colony?
    fgr

Listing Field Values used in a document

Postby Lincoln » Sat, 06 Mar 2004 07:50:55 GMT

Hello, 

  I have received a document with a ton of fields. I would 
like to find a way to extract the field names and 
properties to a separate list for review. Can this be 
done? I'm using Word 2002.

Thanks in advance for any guidance.

Re: Listing Field Values used in a document

Postby Jezebel » Sat, 06 Mar 2004 08:21:05 GMT

You could use this macro, which lists all fields in the document in the
immediate window. You can cut and paste from there.

Sub ListFields()

    Dim pfield As Word.Field
    Dim pRange As Word.Range

    For Each pRange In ActiveDocument.StoryRanges
        Do
            For Each pfield In pRange.Fields
                Debug.Print pfield.Code, pfield.Type, pfield.Kind
            Next
            Set pRange = pRange.NextStoryRange
        Loop Until pRange Is Nothing
    Next

End Sub








Re: Listing Field Values used in a document

Postby macropod » Sat, 06 Mar 2004 17:00:26 GMT

Hi Lincoln,

The following code generates a list of all bookmarks at the end of the
active document, and displays their contents. If you need to do more, you
could incorporate other fields by changing ActiveDocument.Bookmarks to
ActiveDocument.Fields, though some (eg Date) won't have names.



Cheers



Sub GetBkMrks()
If ActiveDocument.Bookmarks.Count > 0 Then
            For Each oBmk In ActiveDocument.Bookmarks
                        With Selection
                                    .EndKey Unit:=wdStory
                                    .InsertAfter oBmk.Name & " "
                                    .EndKey Unit:=wdStory
                                    oBkMrk =
ActiveDocument.Fields.Add(Range:=Selection.Range, Text:=oBmk.Name,
PreserveFormatting:=False)
                                    .InsertAfter vbCrLf
                        End With
            Next oBmk
End If
End Sub








---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.**--****.com/ ).
Version: 6.0.593 / Virus Database: 376 - Release Date: 20/02/2004



Re: Listing Field Values used in a document

Postby Jezebel » Sun, 07 Mar 2004 07:10:02 GMT

Substituting 'Fields' for 'Bookmarks' won't work with this code. First,
fields don't have a Name property, so you won't get any output, just errors.
Second, it would miss all the fields not in the body of the document (eg
headers, footers, footnotes, textboxes, etc).












Re: Listing Field Values used in a document

Postby macropod » Sun, 07 Mar 2004 16:10:49 GMT

i Jezebel,
Yes, you're right about both issues. To address the first issue, the
following code would work:

Sub ListFields()
Dim oFld As Field
If ActiveDocument.Fields.Count > 0 Then
For Each oFld In ActiveDocument.Fields
With Selection
.EndKey Unit:=wdStory
.InsertAfter vbCrLf
.EndKey Unit:=wdStory
.TypeText Text:="{" & oFld.Code & "}, " & oFld.Result
End With
Next oFld
End If
End Sub

To address the second issue, additional code could be used to loop through
headers, footers & shapes as with the following field updating macro (which
might be useful to run before running ListFields):

Sub RefreshFields()
Dim oSection As Section, shp as Shape, oHeadFoot As HeaderFooter
ActiveDocument.Fields.Update
For Each oSection In ActiveDocument.Sections
For Each oHeadFoot In oSection.Footers
If Not oHeadFoot.LinkToPrevious Then oHeadFoot.Range.Fields.Update
Next
For Each oHeadFoot In oSection.Headers
If Not oHeadFoot.LinkToPrevious Then oHeadFoot.Range.Fields.Update
Next
Next
If ActiveDocument.Shapes.Count > 0 Then
For Each shp In doc.Shapes
With shp.TextFrame
If .HasText Then .TextRange.Fields.Update
End With
Next
End If
End Sub

Cheers

"Jezebel" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
errors.
you


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.614 / Virus Database: 393 - Release Date: 5/03/2004



Re: Listing Field Values used in a document

Postby Jezebel » Sun, 07 Mar 2004 16:16:36 GMT

eems to me the code I posted in my original response is a simpler solution
still, that solves both problems. Replace the debug.print with Insert
statements if you want the output into a document --

Dim pfield As Word.Field
Dim pRange As Word.Range

For Each pRange In ActiveDocument.StoryRanges
Do
For Each pfield In pRange.Fields
Debug.Print pfield.Code, pfield.Type, pfield.Kind
Next
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next







"macropod" < XXXX@XXXXX.COM (del NO.SPAM)> wrote in message
news:c2btch$1pm1p5$ XXXX@XXXXX.COM ...
(which



Similar Threads:

1.Using control values within IF field

Hello,

I'm using Word2003 and I would like to use the result from a check box (i.e. 
True or False) in an IF field/function, but don't know how to.
I've gone as far as typing the following, which doesn't work:
IF (Checkbox(Customer).value=true,YES,NO)
I would also like the field to update automatically when the check box value 
changes.
Any suggestions would be greatly appreciated !

thanks in advance

2.using an alphanumeric "word" as a field value in an IF statement

I am attempting to create an IF THEN ELSE statement where the field value I'm 
selecting by is alpha numeric. For example, if I have "06s1" in the compare 
to field, the merged document will always insert the "then" option. If I 
modify it and have "06-s-1" in the compare to field, the funtion works 
properly an inserts the appropriate option - then or else.

Is there some coding I can do so that the function can recognize a "word" 
with both numbers and letters in it?

3.Can I compare more than two merge field values using =AND or =

Thanks Doug.That may, unfortunately, be where I'm at. I'm hoping there's an 
alternative because I'm already close to the max number of columns in the 
data source, and I need to compare the mergefields in multiple, unique 
combinations, which is why I'm hoping to do it in the word doc itself.

Thanks again!


"Doug Robbins - Word MVP" wrote:

> I would suggest that you do the comparing in the data source, moving the 
> data to Excel of Access to do so if necessary.  Both of those programs are 
> better at manipulating data than Word.
> 
> -- 
> 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
> "Rhiannon" < XXXX@XXXXX.COM > wrote in message 
> news: XXXX@XXXXX.COM ...
> > I'm working in Word 2007. I have a list of mergefields (anywhere between 3
> > and 7 depending) that I would like to test the values of - if all of them
> > come back true, return one block of text, else return another block of 
> > text.
> > It works fine when I try and compare the values of two mergefields:
> >
> > {IF { = AND ( { COMPARE {Mergefield 1} = "Y"}, {COMPARE {mergefield 2} <> 
> > 2
> > } ) } = 1 "true" "false" }
> >
> > but as soon as I try and compare the values of three or more mergefields:
> >
> > {IF { = AND ( { COMPARE {Mergefield 1} = "Y"}, {COMPARE {mergefield 2} <> 
> > 2
> > }, { COMPARE {mergefield 3" = "text" } ) } = 1 "true" "false" }
> >
> > it breaks. Is there a way to expand beyond two comparisons, using either 
> > the
> > =AND or the =OR formulas? I'd rather not start nesting piles of these if I
> > can help it. Thanks muchly!! 
> 
> 

4.How do I save a file using the value entered in a text form field

I have a word document that myself and others on my team must fill out 
repeatly. I created a simple template for the basic form to automate the 
process, I would like to automate the "Save As" file name using date from one 
of the "Text form Fields". the file name would be 
"SW_COA_XXXXXX_johnson.doc". The XXXXXX would be the numeric value entered in 
Text Form Field labeled "Text 2".  Can this be done?

Scott

5.Validating field values using an array

The code below is sliced out of my latest efforts. I have a form with
some fields that are mandatory and ortehrs not. to test them I am
trying to use an array with the names of the mandatory fields. But it
will only ever report invalid even when it shold be OK. I#m sure it's
something simple that i can't see for looking. Can anyone spot the
problem?

'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'   Initialise the mandatory fields array etc.
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    valuesMandatoryFields() = Array _
        ("DocTitle", "DocSubject", "DocAuthor",
"DocPublicationStatus", "DocVersion", "DocType")
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'   Check each field
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    For Each conControl In Me.Controls
        If LCase(TypeName(conControl)) = "textbox" Then
            'strMsgInsert = conControl.Name                          '
debug
            'MsgBox "checking field " & strMsgInsert, vbOKOnly
                If IsFieldMandatory(conControl.Name) = True Then    '
it's a mandatory field
                    If Not Len(Trim(conControl.Text)) > 0 Then      '
and they haven't entered anything so
                        booEntryValid = False                       '
set flag so that returns to user
                    End If
                End If
        End If
    Next

'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'   Either exit to process valid or return invalid to user
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    If booEntryValid = True Then
        MsgBox "all Ok"
        Me.Hide                                                    '
valid entry so return control to calling module
    Else                                                            '
invalid entry ask them to try again
        MsgBox "You have not entered one or more of the mandatory
field please try again"
        DocTitle.SetFocus
'set focus to first field before returning control to user
    End If

The Function is like this:

Private Function IsFieldMandatory(varFieldToTest) As Boolean
    For Each varMandatoryField In valuesMandatoryFields
        IsFieldMandatory = (varMandatoryField = varFieldToTest)
    Next
End Function

thank you

luca

6. change drop down list contents based upon value from another list

7. Text fields Values not update before save the document

8. Merge-empty field changes to 0 value in merged document



Return to MS WORD

 

Who is online

Users browsing this forum: No registered users and 11 guest