OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 28-03-2006, 05:22
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default Remove Paragraph marks from artistic text

I have a routine that automatically renames pages. Later I use the page name as the name for a file containing an exported graphic. However, I've discovered a problem if the text I use has extra paragraph returns at the end. This messes up the page name and later causes my export to fail. I want to remove the paragraph marks. I've tried:

Code:
Dim p As Page
 Dim s As Shape
    
    For Each p In ActiveDocument.Pages
    For Each s In p.ActiveLayer.FindShapes(Type:=cdrTextShape)
    Replace(s.Text.Story, Chr(182), "")
    p.Name = Trim(s.Text.Story)
     
    Next s
    Next p
But this doesn't remove the paragraph marks. Is there any way I can do this?

Thanks,

Chris (Hunt)
Reply With Quote
  #2  
Old 28-03-2006, 20:22
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

Chris,

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:

Code:
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:

Code:
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:

Code:
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
  #3  
Old 31-03-2006, 18:48
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default

That's great, Alex. You make it very clear and usable. Since I started using VBA CorelDraw has become twice the program - thanks to you.

Best wishes,

Chris
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Striping a word down to the first letter only knowbodynow CorelDRAW/Corel DESIGNER VBA 9 19-04-2007 15:14
Paragraph Text in Photo-Paint? CgNeophyte General 1 11-04-2006 18:16
corelDRAW paragraph text mirror "bug" hellraeser General 2 08-03-2006 23:17
Rotating multiple artistic text objects geopig CorelDRAW/Corel DESIGNER VBA 6 01-03-2005 16:51
Artistic Text or paragraph invisible after upgrade to v11 ?? tuxedo21 CorelDRAW/Corel DESIGNER VBA 0 26-08-2003 16:27


All times are GMT -5. The time now is 06:56.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com