using word custom field

S

sladjan.parc

1.First how to define custom field in ms word 2003 and ms word 2007
2.How to set values in custom filed outside word application,eg form vb
application
 
D

Doug Robbins - Word MVP

Have you considered using a DOCVARIABLE field

You set the value using

ActiveDocument.Variables("variablename").Value = "somevalue"

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

Abe

Doug,
I have the same question as sladjan. There are instances when a DOCVARIABLE
won't quite do - when you want to set up custom field codes, and custom
behavior for the field, for example. How does one go about writing code to
create a cusom field?

Thanks!
-- Abe
 
D

Doug Robbins - Word MVP

It depends what you mean by custom field.

You can only use the fields that come with word or a combination of those
fields, if a combination is what you mean by custom.

Exactly what is it that you want to do?

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

Abe

Thanks very much for your quick reply.

I was looking at another piece of software (professionally written) that is
designed to work with Word, and which inserts fields in the word document.
When I right-click on those fields and chose "edit field", the field name
comes up as one not included in the field name list, so I assumed it was a
custom field. It appears to be part of an Add-in written for this purpose.
So I was hoping to discover how to go about writing an add-in that created
and managed a custom field.

What I am wanting to do is to insert a field that has maybe three parameters
to it, (a record ID, some text, a page number range) so I can use it from my
VB.NET app to insert and manage formatted reference citations.

Perhaps the DOCVARIABLE could work, but I can't seem to figure out how to
get my rich text into ActiveDocument.variables(i).value. In other parts of
Word, I can just copy it from a rtb in my app and then paste into Word, but
when I paste into document.variables(i).value, the DOCVARIABLE is replaced
with the text, rather than containing the text. I can't use the trick of
formatting the "D" of "DOCVARIABLE" a certain way, because part the text is
not all formatted the same way (for example, only part of it is italicized).

Thanks very much,
Abe
 
C

Cindy M.

Hi Abe,
What I am wanting to do is to insert a field that has maybe three parameters
to it, (a record ID, some text, a page number range) so I can use it from my
VB.NET app to insert and manage formatted reference citations.

Which version of Word are we dealing with, here?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
A

Abe

Thanks for the reply, Cindy. I'm using Word 2007, and coding in Visual
Studio 2008 (VB) on a machine running Vista Ultimate 64-bit.
-- Abe
 
C

Cindy M.

Hi Abe,
I'm using Word 2007, and coding in Visual
Studio 2008 (VB) on a machine running Vista Ultimate 64-bit.

Mmmm. Well, as Doug says, there's no way to create custom fields in Word, although
the Private field can be used to store things in the text flow. The problem here,
though, is "formatted".

I'm inclined to say you should store the information as WordProcessingML (2003) or
WordOpenXML (2007). That's a plain string, but it carries the formatting
information (similar to HTML). You'll find more information about the actual XML
vocabulary at OpenXMLDeveloper.org and in MSDN.

As to the storage medium: just how susceptible is this going to be to accidental
user-deletion? How do you envision the user will be working with these documents?

I'm thinking that either XML nodes might be suitable as "markers". You could store
the things the user shouldn't see as Attributes.

ContentControls linked or associated to a CustomXMLPart might be another
possibility. The CXP can contain additional elements and attributes for storing
data. The only problem with this is that a rich text content control cannot be
directly linked to a CXP. But depending on how everything is supposed to "mesh",
there might be a way to swing it.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in
the newsgroup and not by e-mail :)
 
A

Abe

Thanks, Cindy. In fact I just ran across the CustomXMLPart yesterday as I
was digging around, and that looks like it might work, but I understand very
little about it so I'll have to go do some studying up on it. I was hoping
to maintain control over how Word displays (formats) the various elements
contained within the XML string, so that for example Author names would be in
normal text and the Title string would be italicized. That's where the
notion of a "custom field" came in - so it would be my code that told the
field how to display its contents.

Appreciate the help. I'm off to study up on CXP's!
-- Abe
 
C

Cindy M.

Hi Abe,
In fact I just ran across the CustomXMLPart yesterday as I
was digging around, and that looks like it might work, but I understand very
little about it so I'll have to go do some studying up on it. I was hoping
to maintain control over how Word displays (formats) the various elements
contained within the XML string, so that for example Author names would be in
normal text and the Title string would be italicized. That's where the
notion of a "custom field" came in - so it would be my code that told the
field how to display its contents.

OK, that should be no problem if you use ContentControls in the document. You
can assign a Style to a content control to ensure it appears as you wish. Things
only start to get complicated if you want "mixed styles" within a single content
control.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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