![]() |
#1
|
|||
|
|||
![]()
Please, can you help me with VBA code for CorelDraw 12 or 3X?
In a 20-page CorelDraw document, I need a macro that selects a specific text string, and changes the font size (of only the selected text string). Each page has several text objects. I don't know how to identify the exact text object that contains the text string, but guess the macro can search through all text objects on the page. Optimization is not important here. Goto page Find/Select "My Text String That I Want to Change the Size Of" Apply font size 8, face Arial Goto next page |
#2
|
||||
|
||||
![]()
it will ask you twice. first time for string you search, second time for font name and size (separated by comma ",")
Code:
Sub changeFont() Dim p As Page, oldP As Page, sh As Shape, lookFor As String, i As Long, s As String Dim targetFont As String, targetSize As Integer, report As String, cnt As Long On Error Resume Next lookFor = InputBox("What to search", "text properties replace") If lookFor = "" Then Exit Sub s = InputBox("FontName, Size", "text properties replace", "Arial,8"): i = InStr(s, ",") If i = 0 Then targetSize = 8 Else targetSize = Val(Mid(s, i + 1)): s = left(s, i - 1) targetFont = Trim(s): If targetSize = 0 Then targetSize = 8 report = "": Set oldP = ActivePage ActiveDocument.BeginCommandGroup "Replace " + lookFor For Each p In ActiveDocument.Pages p.Activate For Each sh In p.FindShapes If sh.Type = cdrTextShape Then i = InStr(UCase(sh.Text.Story), UCase(lookFor)) Do While i > 0 cnt = cnt + 1 With sh.Text.Range(i - 1, i + Len(lookFor) - 1) .Font = targetFont: .Size = targetSize End With i = InStr(i + 1, UCase(sh.Text.Story), UCase(lookFor)) Loop End If Next sh If cnt > 0 Then _ report = report + "Page " + CStr(p.Index) + ": " + CStr(cnt) + " times, ": cnt = 0 Next p oldP.Activate: ActiveDocument.EndCommandGroup MsgBox IIf(report = "", "Not found", report) End Sub |
#3
|
|||
|
|||
![]()
wOxxOm:
One million thank yous! You are a total genius! The VBA you wrote worked perfectly! How in the world did you do that so quickly???!!! Wow! Thank you, again. |
#4
|
||||
|
||||
![]() Quote:
You're welcome, moreover this script will be useful for me too, by the way did you try Welcomescreen replacement - my beloved pet macro for CorelDraw? It's here on forums |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
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 |
Changing text size in CD12 | knowbodynow | CorelDRAW/Corel DESIGNER VBA | 10 | 07-03-2006 07:13 |
how to specify the font size in inches | bbolte | CorelDRAW/Corel DESIGNER VBA | 14 | 26-01-2005 22:19 |
InsertAfter - Retain Font Size | Craig Tucker | CorelDRAW/Corel DESIGNER VBA | 3 | 07-01-2005 07:42 |
Reading Font Properties from selected text in CD9 | sherman01 | CorelDRAW/Corel DESIGNER VBA | 2 | 24-11-2004 07:59 |