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 03-03-2006, 07:07
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default Adding text via VBA

I have another question about text. Is it possible to use vba to add a specific text string to every artistic text object on a particular layer? I'd like to be able to add txg to the end of every piece of text. The reason is if I can add txg then when I centre the text it will centre as text on the page. Without adding a string text missing an ascender or descender will not line up correctly. Once hte text is centred I can then do a search and replace and remove txg leaving me with correctly positioned text.

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

Here is the code to go through all text objects on the current layer and add "txg" at the end:

Code:
Sub AddTXG()
    Dim s As Shape
    For Each s In ActiveLayer.Shapes.FindShapes(Type:=cdrTextShape)
        s.Text.Story.InsertAfter "txg"
    Next s
End Sub
And here is the one which goes through all the text objects on the current page and removes the trailing "txg":

Code:
Sub RemoveTXG()
    Dim s As Shape
    Dim tr As TextRange
    For Each s In ActivePage.Shapes.FindShapes(Type:=cdrTextShape)
        If Right(s.Text.Story, 3) = "txg" Then
            Set tr = s.Text.Story.Duplicate()
            tr.Start = tr.End - 3
            tr.Delete
        End If
    Next s
End Sub
Reply With Quote
  #3  
Old 03-03-2006, 09:15
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default

Thanks Alex, that's just what I asked for. I've just finished testing an alternative solution which seems to work for what I have in mind. Since I didn't know how to insert text I figured out a way to temporarily change the vowels:

s.Text.Replace "a", "1tag1", True, ReplaceAll:=True
s.Text.Replace "e", "2teg2", True, ReplaceAll:=True
s.Text.Replace "i", "3tig3", True, ReplaceAll:=True
s.Text.Replace "o", "4tog4", True, ReplaceAll:=True
s.Text.Replace "u", "5tug5", True, ReplaceAll:=True
s.AlignToPageCenter cdrAlignHCenter + cdrAlignVCenter, cdrTextAlignBoundingBox
s.Text.Replace "1tag1", "a", True, ReplaceAll:=True
s.Text.Replace "2teg2", "e", True, ReplaceAll:=True
s.Text.Replace "3tig3", "i", True, ReplaceAll:=True
s.Text.Replace "4tog4", "o", True, ReplaceAll:=True
s.Text.Replace "5tug5", "u", True, ReplaceAll:=True

Needless to say your way leaves my homespun method flapping in the mud. I've only just joined today and I've receive brilliant advice. It must be brilliant because I think I can understand and use it!

Thanks again,

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
Adding a button to toolbars to run a VBA macro Alex FAQ 4 10-05-2007 08:07
Text selection and sizing ddonnahoe CorelDRAW/Corel DESIGNER VBA 5 17-05-2005 13:19
format text dialog box implement graphicdesigner CorelDRAW/Corel DESIGNER VBA 5 22-12-2004 13:37
Reset text after text compression. Bellekom CorelDRAW/Corel DESIGNER VBA 2 05-05-2004 06:14
Create text in PP with VBA adriano Corel Photo-Paint VBA 1 07-01-2003 17:09


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


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