Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Word Constant Values

Status
Not open for further replies.

IanPatUE

Technical User
Sep 23, 2001
5
AU
Hi,

I'm having trouble displaying information from a variety of Word constants:

For instance:

PageNumber = Selection.Information(wdActiveEndPageNumber)
MsgBox (PageNumber)

works OK but:

DocTitle = ActiveDocument.Fields(wdFieldTitle).Result
MsgBox (DocTitle)

returns a message saying that the member of the Collection does not exist.

Doing:

DocTitle = ActiveDocument.Fields.Count
MsgBox (DocTitle)

returns a 1 after Inserting a Field of type Title into the document. This seems to indicate that the wdFieldType Word constants do not have values until they are inserted into the document. Is this correct?

I would like to know how to assign the text in the Title property of the document to a variable, which I may then display. How is this achieved?

Many thanks,

Ian P.
 
Hi,

Just to follow up a little on my previous post:

TheTitle = ActiveDocument.BuiltInDocumentProperties(1)
MsgBox (TheTitle)

displays the document title property for the document. However, I would still like to know how to get the text information out of a WdFieldType constant.

Many thanks,

Ian P.
 
wdFieldTitle, one of the wdFieldType constants, has a value of 15 therefore your code is looking for the 15th field in the document, which doesnt exist.

for lngField = 1 to activedocument.fields.count
msgbox ActiveDocument.Fields(lngField).result
next lngfield

Will display the values of all the fields in the document.

Comparing the ActiveDocument.Fields(x).Type to the various wdFieldType values will determine what type of field it is. e.g.

if ActiveDocument.Fields(1).Type = wdFieldTitle then
msgbox "field number 1 is a Title"
end if

HTH

M :)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top