Hello. I have put together this code but it seems I missed something.
All help is appreciated greatly.
1 2 3 4 5 6 7 8 9
Sub ReplaceTextCurrentPage() Dim txtFIND As String Dim txtREPLACE As String txtFIND = ActiveDocument.FindShape("date") txtREPLACE = CStr(Date) ActivePage.TextReplace txtFIND, txtREPLACE, True, False End Sub
actually this is the code...
1 2 3 4 5 6 7 8 9 10
Sub ReplaceText() Dim txtFIND As String 'The word you want to find and replace Dim txtREPLACE As String 'The new word to replace the old Dim s As Shape ActivePage.Layers("Titleblock").Activate txtFIND = "0/0/2020" txtREPLACE = CStr(Date) ActivePage.Layers("Titleblock").TextReplace txtFIND, txtREPLACE, True, False End Sub
try this (not tested)
Sub ReplaceText() Dim txtFIND As String 'The word you want to find and replace Dim txtREPLACE As String 'The new word to replace the old Dim s As Shape ActivePage.Layers("Titleblock").Activate txtFIND = "0/0/2020" txtREPLACE = CStr(Date)
ActivePage.TextReplace txtFIND, txtREPLACE, True, FalseEnd Sub
you can also try to look here
https://community.coreldraw.com/talk/coreldraw_graphics_suite_x6/f/coreldraw-graphics-suite-x6/50547/i-am-looking-for-a-way-to-make-coreldraw-x6-automatically-insert-the-current-time-and-date-into-a-specific-area-on-a-drawing/240510#240510
I tried a very simple one:ActivePage.TextReplace "foo", "bar", True, FalseIt works on text when it is on a page layer, but not when it is on a master layer.
If that's a limitation of the Page.TextReplace method, then you might try something like this instead.
Sub test_replace_text() Dim sr As ShapeRange Dim s As Shape Set sr = ActivePage.FindShapes(, cdrTextShape) For Each s In sr s.Text.Story = Replace(s.Text.Story, "foo", "bar") Next s End Sub
hEY Eskimo. What does this new code you posted do exactly?
Here is one that is a little bit more elaborate:
Sub replace_date_placeholder_text() Dim sr As ShapeRange Dim s As Shape Dim strNewDate As String Dim strOrig As String Dim strReplaced As String Const strDatePlaceholder As String = "0/0/2020" strNewDate = Format(Now, "m/d/yyyy") Set sr = ActivePage.FindShapes(, cdrTextShape) For Each s In sr strOrig = s.Text.Story strReplaced = Replace(strOrig, strDatePlaceholder, strNewDate) If strOrig <> strReplaced Then s.Text.Story = strReplaced End If Next s End Sub
nailed it Eskimo. Thanks for your help and thanks Mek.
grogo said:nailed it Eskimo. Thanks for your help and thanks Mek.
Hey, I learned something new - that Page.TextReplace doesn't seem to go after shapes on master layers.
Some of the stuff involving master layers just gives me fits.