I added a property 'Address' in a word document and defined a field link
with this property.

I got a string, ie address consists of street name, postcode, state name
separated by a return character.
Is it possible to display the address in several lines?

Re: Document Property to display more than 1 line by Greg

Greg
Mon Dec 11 15:21:04 CST 2006

Lene,

While your code appears to work, it seems a bit like driving a tack
with a sledge hammer.

I have used "Replace" build the insert string as follows:

Sub ScratchMacro()
Dim strName As String
Dim strInsert As String
Dim oRng As Range
Set oRange = Selection.Range
strPropName = "Address"
On Error GoTo Err_Handler:
strInsert = ActiveDocument.CustomDocumentProperties(strName).Value
strInsert = Replace(strInsert, "#", Chr(11))
oRng.InsertAfter strInsert
Exit Sub
Err_Handler:
If Err.Number = 5 Then
MsgBox "The docProperty " & Chr(34) & strName & Chr(34) _
& " is not found in this document."
End If
End Sub





Lene Fredborg wrote:
> Word does not allow property values with line breaks and a field cannot span
> more than one line. However, by making a minor change to the property values
> and by using a macro, you can handle addresses and other "multi-line" text
> strings as properties anyway.
>
> Below you will find a macro that fetches the value of a custom document
> property named "Address". In order for the macro to work, separate the
> different parts of the "Address" value (street name, postcode, state name,
> etc.) by # (can be replaced by any other character that is not used in your
> addresses). The macro does not insert a property field but creates a new
> string in which all # are replaced by manual line breaks (chr(11)). This
> string is inserted at the end of the selection. The macro also works if your
> addresses consist of more or less than 3 parts.
>
> Example:
>
> Property name: "Address"
> Property value: "MyStreetName 23#1234 MyCity#MyCountry"
>
> Result in the document:
>
> MyStreetName 23
> 1234 MyCity
> MyCountry
>
> Here is the macro:
>
> Sub InsertProperty_MultiLine()
>
> Dim oProp As DocumentProperty
> Dim strPropName As String
> Dim StrInsert As String
> Dim bPropFound As Boolean
> Dim oRange As Range
> Dim oArray As Variant
> Dim n As Long
>
> 'REPLACE "Address" by the name of your property
> strPropName = "Address"
>
> 'Define the place to insert the address
> Set oRange = Selection.Characters.Last
> '=========================
> 'Check that strPropName is found before inserting
> For Each oProp In ActiveDocument.CustomDocumentProperties
> If oProp.Name = strPropName Then
> bPropFound = True
> 'get property value
> 'Split in array
> 'Replace all # in value by manual line breaks
> oArray = Split(oProp.Value, "#")
> 'Combine each part with a manual line break between
> StrInsert = ""
> 'Build the string
> For n = LBound(oArray) To UBound(oArray)
> StrInsert = StrInsert & oArray(n) & Chr(11)
> Next n
> 'Remove last chr(11) and string is correct
> StrInsert = Left(StrInsert, Len(StrInsert) - 1)
> 'Insert text in document
> oRange.InsertAfter StrInsert
> GoTo LineExit
> End If
> Next oProp
> '=========================
> 'Show msg is property not found
> If bPropFound = False Then
> MsgBox "Custom document property " & _
> strPropName & " not found.", vbOKOnly, _
> "Property missing"
> GoTo LineExit
> End If
>
> LineExit:
> Set oRange = Nothing
> End Sub
>
> --
> Regards
> Lene Fredborg
> DocTools - Denmark
> www.thedoctools.com
> Document automation - add-ins, macros and templates for Microsoft Word
>
>
> "Alan T" wrote:
>
> > I added a property 'Address' in a word document and defined a field link
> > with this property.
> >
> > I got a string, ie address consists of street name, postcode, state name
> > separated by a return character.
> > Is it possible to display the address in several lines?
> >
> >
> >


Re: Document Property to display more than 1 line by Alan

Alan
Mon Dec 11 18:55:58 CST 2006

Hi, thanks for all advices.

The problem is the address string was return from a component, the address
lines are separated by a carriage return key, ie a little vertical
rectangle.

In the Replace function,

>>> strInsert = Replace(strInsert, "#", Chr(11))
what should I put into the "#" ?

"Lene Fredborg" <lf@REMOVETHISthedoctools.com> wrote in message
news:BB6E13B1-F43C-4FE1-995B-16FA17DC1245@microsoft.com...
> Greg,
>
> I fully agree - "Replace" is absolutely better than the solution I
> suggested. Thanks.
> --
> Lene
>
> "Greg Maxey" wrote:
>
>> Lene,
>>
>> While your code appears to work, it seems a bit like driving a tack
>> with a sledge hammer.
>>
>> I have used "Replace" build the insert string as follows:
>>
>> Sub ScratchMacro()
>> Dim strName As String
>> Dim strInsert As String
>> Dim oRng As Range
>> Set oRange = Selection.Range
>> strPropName = "Address"
>> On Error GoTo Err_Handler:
>> strInsert = ActiveDocument.CustomDocumentProperties(strName).Value
>> strInsert = Replace(strInsert, "#", Chr(11))
>> oRng.InsertAfter strInsert
>> Exit Sub
>> Err_Handler:
>> If Err.Number = 5 Then
>> MsgBox "The docProperty " & Chr(34) & strName & Chr(34) _
>> & " is not found in this document."
>> End If
>> End Sub
>>
>>
>>
>>
>>
>> Lene Fredborg wrote:
>> > Word does not allow property values with line breaks and a field cannot
>> > span
>> > more than one line. However, by making a minor change to the property
>> > values
>> > and by using a macro, you can handle addresses and other "multi-line"
>> > text
>> > strings as properties anyway.
>> >
>> > Below you will find a macro that fetches the value of a custom document
>> > property named "Address". In order for the macro to work, separate the
>> > different parts of the "Address" value (street name, postcode, state
>> > name,
>> > etc.) by # (can be replaced by any other character that is not used in
>> > your
>> > addresses). The macro does not insert a property field but creates a
>> > new
>> > string in which all # are replaced by manual line breaks (chr(11)).
>> > This
>> > string is inserted at the end of the selection. The macro also works if
>> > your
>> > addresses consist of more or less than 3 parts.
>> >
>> > Example:
>> >
>> > Property name: "Address"
>> > Property value: "MyStreetName 23#1234 MyCity#MyCountry"
>> >
>> > Result in the document:
>> >
>> > MyStreetName 23
>> > 1234 MyCity
>> > MyCountry
>> >
>> > Here is the macro:
>> >
>> > Sub InsertProperty_MultiLine()
>> >
>> > Dim oProp As DocumentProperty
>> > Dim strPropName As String
>> > Dim StrInsert As String
>> > Dim bPropFound As Boolean
>> > Dim oRange As Range
>> > Dim oArray As Variant
>> > Dim n As Long
>> >
>> > 'REPLACE "Address" by the name of your property
>> > strPropName = "Address"
>> >
>> > 'Define the place to insert the address
>> > Set oRange = Selection.Characters.Last
>> > '=========================
>> > 'Check that strPropName is found before inserting
>> > For Each oProp In ActiveDocument.CustomDocumentProperties
>> > If oProp.Name = strPropName Then
>> > bPropFound = True
>> > 'get property value
>> > 'Split in array
>> > 'Replace all # in value by manual line breaks
>> > oArray = Split(oProp.Value, "#")
>> > 'Combine each part with a manual line break between
>> > StrInsert = ""
>> > 'Build the string
>> > For n = LBound(oArray) To UBound(oArray)
>> > StrInsert = StrInsert & oArray(n) & Chr(11)
>> > Next n
>> > 'Remove last chr(11) and string is correct
>> > StrInsert = Left(StrInsert, Len(StrInsert) - 1)
>> > 'Insert text in document
>> > oRange.InsertAfter StrInsert
>> > GoTo LineExit
>> > End If
>> > Next oProp
>> > '=========================
>> > 'Show msg is property not found
>> > If bPropFound = False Then
>> > MsgBox "Custom document property " & _
>> > strPropName & " not found.", vbOKOnly, _
>> > "Property missing"
>> > GoTo LineExit
>> > End If
>> >
>> > LineExit:
>> > Set oRange = Nothing
>> > End Sub
>> >
>> > --
>> > Regards
>> > Lene Fredborg
>> > DocTools - Denmark
>> > www.thedoctools.com
>> > Document automation - add-ins, macros and templates for Microsoft Word
>> >
>> >
>> > "Alan T" wrote:
>> >
>> > > I added a property 'Address' in a word document and defined a field
>> > > link
>> > > with this property.
>> > >
>> > > I got a string, ie address consists of street name, postcode, state
>> > > name
>> > > separated by a return character.
>> > > Is it possible to display the address in several lines?
>> > >
>> > >
>> > >
>>
>>



Re: Document Property to display more than 1 line by Graham

Graham
Tue Dec 12 00:07:49 CST 2006

Select, then use the following macro to identify the character

Sub ANSIValue()
S1$ = "Because the selected text contains"
S2$ = " characters, not all of the ANSI values will be displayed."
S3$ = "ANSI Value ("
S4$ = " characters in selection)"
S5$ = " character in selection)"
S6$ = "Text must be selected before this macro is run."
S7$ = "ANSI Value"
Dim strSel As String
Dim strNums As String
Dim LastFourChar As String
Dim iPos As Integer
strSel = Selection.Text
If Len(strSel) > 0 Then
For i = 1 To Len(strSel)
strNums = strNums + Str(Asc(Mid(strSel, i)))
Next i
strNums = LTrim(strNums)
If Len(strNums) > 255 Then
LastFourChar = Mid(strNums, 252, 4)
strNums = Left(strNums, 251) + Left(LastFourChar, _
4 - InStr(" ", LastFourChar))
MsgBox S1$ + Str(Len(strSel)) + S2$
End If
If Len(strSel) = 1 Then S4$ = S5$
MsgBox strNums, 0, S3$ + LTrim(Str(Len(strSel))) + S4$
Else
MsgBox S6$, 0, S7$
End If
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Alan T wrote:
> Hi, thanks for all advices.
>
> The problem is the address string was return from a component, the
> address lines are separated by a carriage return key, ie a little
> vertical rectangle.
>
> In the Replace function,
>
>>>> strInsert = Replace(strInsert, "#", Chr(11))
> what should I put into the "#" ?
>
> "Lene Fredborg" <lf@REMOVETHISthedoctools.com> wrote in message
> news:BB6E13B1-F43C-4FE1-995B-16FA17DC1245@microsoft.com...
>> Greg,
>>
>> I fully agree - "Replace" is absolutely better than the solution I
>> suggested. Thanks.
>> --
>> Lene
>>
>> "Greg Maxey" wrote:
>>
>>> Lene,
>>>
>>> While your code appears to work, it seems a bit like driving a tack
>>> with a sledge hammer.
>>>
>>> I have used "Replace" build the insert string as follows:
>>>
>>> Sub ScratchMacro()
>>> Dim strName As String
>>> Dim strInsert As String
>>> Dim oRng As Range
>>> Set oRange = Selection.Range
>>> strPropName = "Address"
>>> On Error GoTo Err_Handler:
>>> strInsert = ActiveDocument.CustomDocumentProperties(strName).Value
>>> strInsert = Replace(strInsert, "#", Chr(11))
>>> oRng.InsertAfter strInsert
>>> Exit Sub
>>> Err_Handler:
>>> If Err.Number = 5 Then
>>> MsgBox "The docProperty " & Chr(34) & strName & Chr(34) _
>>> & " is not found in this document."
>>> End If
>>> End Sub
>>>
>>>
>>>
>>>
>>>
>>> Lene Fredborg wrote:
>>>> Word does not allow property values with line breaks and a field
>>>> cannot span
>>>> more than one line. However, by making a minor change to the
>>>> property values
>>>> and by using a macro, you can handle addresses and other
>>>> "multi-line" text
>>>> strings as properties anyway.
>>>>
>>>> Below you will find a macro that fetches the value of a custom
>>>> document property named "Address". In order for the macro to work,
>>>> separate the different parts of the "Address" value (street name,
>>>> postcode, state name,
>>>> etc.) by # (can be replaced by any other character that is not
>>>> used in your
>>>> addresses). The macro does not insert a property field but creates
>>>> a new
>>>> string in which all # are replaced by manual line breaks (chr(11)).
>>>> This
>>>> string is inserted at the end of the selection. The macro also
>>>> works if your
>>>> addresses consist of more or less than 3 parts.
>>>>
>>>> Example:
>>>>
>>>> Property name: "Address"
>>>> Property value: "MyStreetName 23#1234 MyCity#MyCountry"
>>>>
>>>> Result in the document:
>>>>
>>>> MyStreetName 23
>>>> 1234 MyCity
>>>> MyCountry
>>>>
>>>> Here is the macro:
>>>>
>>>> Sub InsertProperty_MultiLine()
>>>>
>>>> Dim oProp As DocumentProperty
>>>> Dim strPropName As String
>>>> Dim StrInsert As String
>>>> Dim bPropFound As Boolean
>>>> Dim oRange As Range
>>>> Dim oArray As Variant
>>>> Dim n As Long
>>>>
>>>> 'REPLACE "Address" by the name of your property
>>>> strPropName = "Address"
>>>>
>>>> 'Define the place to insert the address
>>>> Set oRange = Selection.Characters.Last
>>>> '=========================
>>>> 'Check that strPropName is found before inserting
>>>> For Each oProp In ActiveDocument.CustomDocumentProperties
>>>> If oProp.Name = strPropName Then
>>>> bPropFound = True
>>>> 'get property value
>>>> 'Split in array
>>>> 'Replace all # in value by manual line breaks
>>>> oArray = Split(oProp.Value, "#")
>>>> 'Combine each part with a manual line break between
>>>> StrInsert = ""
>>>> 'Build the string
>>>> For n = LBound(oArray) To UBound(oArray)
>>>> StrInsert = StrInsert & oArray(n) & Chr(11)
>>>> Next n
>>>> 'Remove last chr(11) and string is correct
>>>> StrInsert = Left(StrInsert, Len(StrInsert) - 1)
>>>> 'Insert text in document
>>>> oRange.InsertAfter StrInsert
>>>> GoTo LineExit
>>>> End If
>>>> Next oProp
>>>> '=========================
>>>> 'Show msg is property not found
>>>> If bPropFound = False Then
>>>> MsgBox "Custom document property " & _
>>>> strPropName & " not found.", vbOKOnly, _
>>>> "Property missing"
>>>> GoTo LineExit
>>>> End If
>>>>
>>>> LineExit:
>>>> Set oRange = Nothing
>>>> End Sub
>>>>
>>>> --
>>>> Regards
>>>> Lene Fredborg
>>>> DocTools - Denmark
>>>> www.thedoctools.com
>>>> Document automation - add-ins, macros and templates for Microsoft
>>>> Word "Alan T" wrote:
>>>>
>>>>> I added a property 'Address' in a word document and defined a
>>>>> field link
>>>>> with this property.
>>>>>
>>>>> I got a string, ie address consists of street name, postcode,
>>>>> state name
>>>>> separated by a return character.
>>>>> Is it possible to display the address in several lines?