Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
Alan T Alan T is offline
external usenet poster
 
Posts: 3
Default Document Property to display more than 1 line

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?


  #2   Report Post  
Posted to microsoft.public.word.newusers
Lene Fredborg Lene Fredborg is offline
external usenet poster
 
Posts: 1,291
Default Document Property to display more than 1 line

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?



  #3   Report Post  
Posted to microsoft.public.word.newusers
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default Document Property to display more than 1 line

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).V alue
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?




  #4   Report Post  
Posted to microsoft.public.word.newusers
Lene Fredborg Lene Fredborg is offline
external usenet poster
 
Posts: 1,291
Default Document Property to display more than 1 line

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).V alue
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?





  #5   Report Post  
Posted to microsoft.public.word.newusers
Alan T Alan T is offline
external usenet poster
 
Posts: 3
Default Document Property to display more than 1 line

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" wrote in message
...
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).V alue
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?









  #6   Report Post  
Posted to microsoft.public.word.newusers
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Document Property to display more than 1 line

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" wrote in message
...
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).V alue
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?



  #7   Report Post  
Posted to microsoft.public.word.newusers
Lene Fredborg Lene Fredborg is offline
external usenet poster
 
Posts: 1,291
Default Document Property to display more than 1 line

When you only need to find the character code of a _single_ character, you
can do as follows:

In the document, select the character (or position the insertion marker to
the left of it)
Open the Immediate window in VBA and type:
?asc(selection.characters.first)
Hit Return to display the character code.

If you often need to determine a _single_ character code, it may be easier
to have a macro that displays the value. The macro below can be used:

Sub ShowCharacterCode()
Displays character code of first character in selection
With Selection.Characters
MsgBox "Character: " & .First & vbCr & _
"Code: " & Asc(.First)
End With
End Sub

--
Regards
Lene Fredborg
DocTools Denmark
www.thedoctools.com
Document automation add-ins, macros and templates for Microsoft Word


"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" wrote in message
...
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).V alue
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?








Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting title document property affects retrieval of author [email protected] Microsoft Word Help 0 January 25th 06 06:06 AM
Setting title document property affects retrieval of author [email protected] Microsoft Word Help 0 January 25th 06 06:06 AM
How to remove a solid line from a document? Dean Page Layout 1 August 18th 05 07:23 PM
Templates gman Page Layout 17 April 22nd 05 06:35 PM
Why is line spacing different between printers in document Office. Gmsmith10 Microsoft Word Help 1 January 18th 05 12:32 AM


All times are GMT +1. The time now is 09:51 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"