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!

Word 2003 -- custom doc property question

Status
Not open for further replies.

Walipala

Technical User
Jan 5, 2007
21
US
Hi again folks. I don't know if this is specifically a VBA question, though I'll be using VBA to implement it. I want to create a custom document property, say "modeNo", with the value being an en-dash. This isn't something I can just type in though. En-dash does have a unicode value, U+2013 or whatever it is, but that of course won't appear in the document as an en-dash. It just sees this as string of characters, so that's what I will get.

Does anyone know of a way code this so that the inserted field in the document appears as an en-dash? Thanks again in advance.
 
You wanted this ?
ChrW(&H2013)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Maybe there's more to that then meets the eye. Putting that in the "text" value field for the custom property just means that "ChrW(&H2013)" appears in the document when a field is added.
 
Well... I was just doing the creating and field insertion manually, to see what would appear. If I were to code it, it would look something like this (please don't laugh):

To create the custom property and assign it the value provided above:
Code:
Dim nDash As String
    nDash = "ChrW(&H2013)"

    ActiveDocument.CustomDocumentProperties.Add Name:="nDashProperty", _
       LinkToContent:=False, Value:=nDash, Type:=msoPropertyTypeString

To insert the new property as a field at a selected place in doc:
Code:
   Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
        "DOCPROPERTY  nDashProperty ", PreserveFormatting:=True
 
Aha! you were asking about code and then tried to do it manually - the two are different.

To do it manually you can press Alt, type 8812, release Alt - just as you can in a document.

Does the code work?

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Well, I was doing it manually because I don't know how to code it. Manually it works fine. I can type Alt+8211 and an en-dash appears in the Properties window. I can then insert a field linked to that property and the en-dash appears just fine.

What I really want to do is have a macro that creates a property with an en-dash as the value, for the purpose of inserting that property as a field in various parts of the document. The code above is probably a little clunky but actually works fine for this when using regular text strings like names, dates, etc.

I guess this all boils down to the question, how can I code Alt+8211 ?
 
I'm getting déjà vu.

You code it as ChrW(&H2013). Now I look more closely at your code I see you have:
Code:
nDash = "ChrW(&H2013)"
where you should have:
Code:
nDash = ChrW(&H2013)
In other words you don't want the quotes around it.


Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Well I'll be...

Thanks for pointing out that should-have-been-obvious lil' detail. And thanks again to PHV for originally providing it. (This is what happens when I try to do this kind of stuff at work.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top