Replacing line breaks

  • Thread starter Thread starter Ronaldo
  • Start date Start date
R

Ronaldo

Hi.

Is there a way to incorporate line breaks in replaces (ctrl-H), in either
the Find field or the Replace field?

This would save me massive amounts of time and I would really appreciate it
if someone could tell me.
 
I am trying to find all instances of ". " (a period followed by a space,
indicating the beginning of another sentence in the same paragraph) and
replace them with "." & vbCrLf (a period followed by a paragraph break) --
(here's my sticky part) -- except when the ". " falls within bullet text.

I tried the example in this thread (SandR), but it removes all existing text
formatting, and I can't figure out how to skip the bullet paragraphs.

Following various examples I found in the PPT VBA Reference as well as
pptfaq.com, I've come up with something that works fairly well, until I hit a
bullet paragraph. At that point, I want to skip ahead, by making the next
Find start after the previously found ". ", but the Find stops here, and I
get an "Object variable or with block variable not set" error.

Here's what I have. Any suggestions?


Sub FindReplaceNotesText()
' Loops through all Notes Body placeholders and changes
' ". " (period space) to a paragraph break

Dim oPres As Presentation
Dim oSl As Slide
Dim oNotesBox As Shape
Dim X As Long
Dim oTxtRng As TextRange
Dim oTmpRng As TextRange
Set oPres = ActivePresentation

For Each oSl In oPres.Slides
With oSl
For X = 1 To oSl.NotesPage.Shapes.Count
If .NotesPage.Shapes(X).Type = msoPlaceholder Then
' The shape is a placeholder
If .NotesPage.Shapes(X).PlaceholderFormat.Type =
ppPlaceholderBody Then
' The shape is a body placeholder
Set oNotesBox = .NotesPage.Shapes(X)
Set oTxtRng = oNotesBox.TextFrame.TextRange
oTxtRng.Select
Set oTmpRng = oTxtRng.Find(FindWhat:=". ")
oTmpRng.Select
Do While Not oTmpRng Is Nothing
If Not oTmpRng.ParagraphFormat.Bullet Then
Set oTmpRng = oTxtRng.Replace(FindWhat:=".
", _
Replacewhat:="." & vbCrLf, After:=2)
oTmpRng.Select
Set oTmpRng = oTxtRng.Find(FindWhat:=". ")
oTmpRng.Select
Else
MsgBox "This is bullet text!"
Set oTxtRng = ActiveWindow.Selection.TextRange
oTxtRng.Select
Set oTmpRng = oTxtRng.Find(FindWhat:=". ",
After:=2)
'here is where I need the search to start
'from where I last stopped, but instead I get an
'Object variable or with block variable not set error
oTmpRng.Select
End If
Loop
End If ' The shape is not a PlaceholderBody
End If ' The shape is not an msoPlaceholder
Next 'X oNotesBox
End With 'oSl
Next ' oSl

End Sub

I'd appreciate any ideas to "fix" what I have, or to go another way entirely.
 
Pulling the arrays out to an external file?

Echo S said:

> Sub SandR()
>
> Dim oSl As Slide
> Dim oSh As Shape
>
> For Each oSl In ActivePresentation.Slides
> For Each oSh In oSl.Shapes
> With oSh
> If .HasTextFrame Then
> If .TextFrame.HasText Then
> With .TextFrame.TextRange
> .Text = Replace(.Text, Chr$(11), vbCrLf)
> ' add more replacements as need be
> ' pipes with "plumbing"
> .Text = Replace(.Text, "|", "lead-pipe-cinch")
> End With
> End If
> End If
> End With
> Next
> Next
>
> End Sub
>

Hi I've got this working for me (thanks)... only now I have way too many terms to search and replace... is there any way I can pull these arrays .Text = Replace(.Text, "|", "lead-pipe-cinch") out of a text/excel file.

My external file has 2 columns. Column A is the text to find and column B is the text to replace the term from column A.

There may be quotes and/or apostrophes, but if search and replace can't deal with that, I can work my way around it.

So I'm looking for a .Text = Replace(.Text, textFromColumnA, textFromColumnB) loop and the way to tell the vb which file to open to look up these terms!
 
Last edited:
Back
Top