OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Corel User Forums > CorelDRAW > Macros/Add-ons

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-08-2008, 14:23
jfelder
Guest
 
Posts: n/a
Default Find/Replace Text in Multiple Open Documents

I have several different ads but all have the same text. I am wanting a macro that will allow me to find a phone number or a date, etc. and change it in all of the open documents.

I have searched the forums and found a few bits of code. I don't know the code well enough to modify it to my needs. I tried recording a macro by doing a Find/Replace Text but it doesn't recognize those dialogs.

I'm using CorelDraw 11.633

Thanks for any help.
Jim
Reply With Quote
  #2  
Old 08-08-2008, 01:43
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default It might help....

Wow, CorelDRAW 11, I don't have that on any machine, so I can't test this under 11 for you. But this works in X4. Hopefully it gives you a start.
Code:
Sub ReplaceTextAcrossOpenDocs()
    Const txtFIND As String = "Blue" 'The word you want to find and replace
    Const txtREPLACE As String = "Yellow" 'The new word to replace the old
    
    Dim d As Document
    Dim p As Page
    Dim s As Shape
    
    For Each d In Documents 'Loop all the open documents
        For Each p In d.Pages 'Loop each page
            For Each s In p.Shapes 'Loop each shape
                If s.Type = cdrTextShape Then 'If the shape is text do the replace
                    s.Text.Story = Replace(s.Text.Story.Text, txtFIND, txtREPLACE)
                End If
            Next s
        Next p
    Next d
End Sub
Best of luck,

-Shelby
Reply With Quote
  #3  
Old 08-08-2008, 02:17
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Even Better....

Even Better try this:
Code:
Sub ReplaceTextAcrossOpenDocs()
    Const txtFIND As String = "Yellow" 'The word you want to find and replace
    Const txtREPLACE As String = "Blue" 'The new word to replace the old
    
    Dim d As Document
    Dim p As Page
    
    For Each d In Documents 'Loop all the open documents
        For Each p In d.Pages 'Loop each page
           p.TextReplace txtFIND, txtREPLACE, True, False
        Next p
    Next d
End Sub
Best of luck,

-Shelby
Reply With Quote
  #4  
Old 08-08-2008, 08:11
jfelder
Guest
 
Posts: n/a
Smile

That is just insane how quick that works. You make it look so easy. The code is so hard to undersand. It's like greek. I've tried to figure these things out from other code and try to modify it to fit my needs but I'm just not grasping it.

Thanks very much for this last code. The first one didn't work for me but the second one did.

Is there a way to prompt me to enter the text to replace or do I just need to change the text to replace in the macro?
Reply With Quote
  #5  
Old 08-08-2008, 13:01
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Prompts...

The easy way is to have two input boxes. If you want it to look nice and only have a single dialog you would need to create and design a form.
Code:
Sub ReplaceTextAcrossOpenDocs()
    Dim txtFIND As String 'The word you want to find and replace
    Dim txtREPLACE As String 'The new word to replace the old
    
    Dim d As Document
    Dim p As Page
    Dim s As Shape
    
    txtFIND = InputBox("Enter the string you wish to replace:", "Replace Text Across OpenDocs")
    txtREPLACE = InputBox("Enter the new string:", "Replace Text Across OpenDocs")
    
    For Each d In Documents 'Loop all the open documents
        For Each p In d.Pages 'Loop each page
           p.TextReplace txtFIND, txtREPLACE, True, False
        Next p
    Next d
End Sub
Good luck,

-Shelby
Reply With Quote
  #6  
Old 08-08-2008, 13:13
jfelder
Guest
 
Posts: n/a
Default

Oh my gosh that is the coolest thing I've seen in a while!!!
That is just awesome. I'm smiling as I'm typing and I laughed out loud when I tried it.

Thank you so much!!

I'll get your "check" in the mail and I'll throw in a batch of chocolate chip cookies too!!

Thank so much!!

Reply With Quote
  #7  
Old 20-01-2009, 12:20
arijit
Guest
 
Posts: n/a
Default Find/Replace text in Multiple documents alongwith open and save

This script almost helps me, I am trying to find a solution almost similar to the script in this thread with following changes -

1. have two folder browsing fields like File converter.gms for choosing source folder and destination folder
2. the input text field, and the output-replace text field
3. And the scripts runs through the entire folder, opens the files in hidden or full mode, saves and close with same name.
Reply With Quote
Reply

Tags
find, macros, replace, text


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
FInd index of shapes grouped with text rubidoux CorelDRAW/Corel DESIGNER VBA 3 07-10-2007 22:00
Find all text and apply text style keytecstaff CorelDRAW/Corel DESIGNER VBA 2 18-05-2006 09:48
Find and Replace Text with Form RVogel CorelDRAW/Corel DESIGNER VBA 1 24-03-2005 09:37
Rotating multiple artistic text objects geopig CorelDRAW/Corel DESIGNER VBA 6 01-03-2005 16:51
Find/Replace with CorelDraw 9 and VB 6 sfldan CorelDRAW/Corel DESIGNER VBA 1 10-07-2003 17:44


All times are GMT -5. The time now is 16:03.


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