View Single Post
Old 28-03-2006, 21:22
Alex's Avatar
Alex Alex is offline
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4


First, to start, a new paragraph mark is represented as a character with code 10, that is, Chr(10), or using predefined VBA's constant vbLf, and not the paragraph sign, Chr(182). Well, this is valid for Paragraph Text only. In Artistic Text object, new line start with character 13, or vbCr for short. This is the same character as soft line return (Shift-Enter) in Paragraph text, because essentially a artistic text object is one single paragraph of text...

The problem number two is that you can't just do something like this:

Replace(s.Text.Story, Chr(182), "")
Just because it will have no effect. The reason for this is that Shape.Text.Story will return the string contained in the text object, then the Replace function will remove the specified character and return the new string which you ignore. You need to use the string returned by the Replace:

s.Text.Story = Replace(s.Text.Story, vbCr, "")
Or, if you don't need to actually change the text object and just use the text contained within it, you can always do something like this:

Sub RenamePage()
    Dim strText As String
    If ActiveShape Is Nothing Then Exit Sub
    If ActiveShape.Type <> cdrTextShape Then Exit Sub
    strText = ActiveShape.Text.Story
    strText = Replace(strText, vbCr, "") ' Remove soft returns
    strText = Replace(strText, vbLf, "") ' Remove paragraph breaks
    strText = Trim(strText) ' Remove any space in front/at the back of the text
    ActivePage.Name = Left(strText, 32) ' Use no more than 32 characters
End Sub
Reply With Quote