Inserting a FIELD programmatically

V

VKY

Hi,

Is there a way to insert a field programmatically or the only way to
insert a field is through the Insert | Fields dialog?

Thanks in advance.
 
J

John Marshall, MVP

You can add fields by code.

Add the Edit date:
vsoCharacters1.AddFieldEx visFCatDateTime, visFCodeEditDate,
visFmtMsoDateLongDay, 1033, 0

Add the Height of the shape:
vsoCharacters1.AddFieldEx visFCatGeometry, visFCodeHeight,
visFmtNumGenNoUnits, 1033, 0

Add the number of pages:
vsoCharacters1.AddFieldEx visFCatPage, visFCodeNumberOfPages,
visFmtNumGenNoUnits, 1033, 0

The easiest way to determine what code you need is to use the Record Macro
feature and then insert the field you want into a shape.

John... Visio MVP

Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm
Need VBA examples? http://www.mvps.org/visio/VBA.htm
Common Visio Questions http://www.mvps.org/visio/common_questions.htm
Visio Wishlist http://www.mvps.org/visio/wish_list.htm
 
V

VKY

Thanks John, and that was before your answer. I kept on googling for an
answer and ended up at your blog, where you wrote about the macro
recorder being a great too. So I recorded it and saw what was going on.

Thanks!!!
 
M

Michel LAPLANE

Very interesting
John Marshall said:
You can add fields by code.

Add the Edit date:
vsoCharacters1.AddFieldEx visFCatDateTime, visFCodeEditDate,
visFmtMsoDateLongDay, 1033, 0

Add the Height of the shape:
vsoCharacters1.AddFieldEx visFCatGeometry, visFCodeHeight,
visFmtNumGenNoUnits, 1033, 0

Add the number of pages:
vsoCharacters1.AddFieldEx visFCatPage, visFCodeNumberOfPages,
visFmtNumGenNoUnits, 1033, 0

The easiest way to determine what code you need is to use the Record Macro
feature and then insert the field you want into a shape.

John... Visio MVP

Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm
Need VBA examples? http://www.mvps.org/visio/VBA.htm
Common Visio Questions http://www.mvps.org/visio/common_questions.htm
Visio Wishlist http://www.mvps.org/visio/wish_list.htm
 

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