Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.word.newusers
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Setting title document property affects retrieval of author | Microsoft Word Help | |||
Setting title document property affects retrieval of author | Microsoft Word Help | |||
How to remove a solid line from a document? | Page Layout | |||
Templates | Page Layout | |||
Why is line spacing different between printers in document Office. | Microsoft Word Help |