Sub RemoveParaOrLineBreaks()
Dim staticTC As String
staticTC = "--:--:--:--,--:--:--:--,10"
Dim static_next_line As String
static_next_line = "80 80 80"
Dim Found As Boolean
Dim boolvar As Boolean
Dim firstsel As Boolean
Dim tpar As Variant
Dim parnum As Variant
Dim slide_s1 As String
Dim slide_s2 As String
slide_s1 = ""
slide_s2 = ""
Dim parasel As String
Dim new_replace As String
Dim vararray() As String
Dim newsel As Range
Dim whole_slide As Range
tpar = ActiveDocument.Paragraphs.count
boolvar = True
firstsel = True
Found = False
slide_s1 = ""
slide_s2 = ""
'Set whole_slide = Selection.Range
'whole_slide.WholeStory
'Set whole_slide = ActiveDocument.Content
Set slidenum = Selection.Range
slidenum.WholeStory
Set whole_doc = Selection.Range
whole_doc.WholeStory
'Do Until boolvar = False
'if this is the first time we're doing program, eval the first section
If firstsel = True Then
'find the first pattern of text: 4 digits followed by a space followed by a colon followed by a line break
parnum = 0
Set whole_slide = ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(14).Range.Start, End:=ActiveDocument.Paragraphs(tpar).Range.End)
MsgBox whole_slide
With whole_slide.Find
.ClearFormatting
.Execute FindText:="^#^#^#^#" & Chr(32) & ":" & Chr(13), Forward:=True, _
Format:=False, Wrap:=wdFindStop
'if we find it, tell us what we found and set found to true
If .Found = True Then
whole_slide.Find.Execute FindText:="^#^#^#^#"
slidenum = whole_slide
continue = True
Found = True
firstsel = False
MsgBox slidenum
MsgBox whole_slide
End If
End With
'if found is still not true, find the second pattern: 4 digits, followed by a letter, followed by a colon followed by a line break
If Found = False Then
With whole_slide.Find
.ClearFormatting
.Execute FindText:="^#^#^#^#^$" & Chr(32) & ":" & Chr(13), Forward:=True, _
Format:=False, Wrap:=wdFindStop
'if we find it, tell us what we found and set found to true. Also, parse found data and set slidenum to actual slide num
If .Found = True Then
whole_slide.Find.Execute FindText:="^#^#^#^#^$"
slidenum = whole_slide
continue = True
Found = True
firstsel = False
'MsgBox slidenum
End If
End With
End If
'if this is not the first time running the program
Else
'MsgBox whole_slide
'parnum = ActiveDocument.Range(0, whole_slide.Paragraphs(1).Range.End).Paragraphs.count
parnum = 13
Set whole_slide = ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(parnum).Range.Start, End:=ActiveDocument.Paragraphs(tpar).Range.End)
MsgBox whole_slide
With whole_slide.Find
.ClearFormatting
.Execute FindText:="^#^#^#^#" & Chr(32) & ":" & Chr(13), Forward:=True, _
Format:=False, Wrap:=wdFindStop
'if we find it, tell us what we found and set found to true
If .Found = True Then
whole_slide.Find.Execute FindText:="^#^#^#^#"
slidenum = whole_slide
continue = True
Found = True
MsgBox whole_slide
'parnum = ActiveDocument.Range(0, whole_slide.Paragraphs(1).Range.End).Paragraphs.count
MsgBox parnum
MsgBox tpar
' MsgBox slidenum
End If
End With
'if found is still not true, find the second pattern: 4 digits, followed by a letter, followed by a colon followed by a line break
If Found = False Then
With whole_slide.Find
.ClearFormatting
.Execute FindText:="^#^#^#^#^$" & Chr(32) & ":" & Chr(13), Forward:=True, _
Format:=False, Wrap:=wdFindStop
'if we find it, tell us what we found and set found to true. Also, parse found data and set slidenum to actual slide num
If .Found = True Then
wholse_slide.Find.Execute FindText:="^#^#^#^#^$"
slidenum = whole_slide
continue = True
Found = True
'MsgBox slidenum
End If
End With
End If
End If
If Found = False Then
Exit Sub
End If
If (continue = True And boolvar = True) Then
'Assign sentence after slide number to slide_s1 var
slide_s1 = whole_slide.Next(Unit:=wdSentence, count:=1)
'Assign second sentence to slide_s2 var
slide_s2 = whole_slide.Next(Unit:=wdSentence, count:=2)
'Check if slide_s2 winds up being part of the next slide. If so, set it to null.
If (slide_s2 Like "*####*" = True) Then
slide_s2 = ""
End If
'Decide if slide has one or two sentences
If Len(slide_s1) <> 0 And Len(slide_s2) < 1 Then
'replace text and move whole_slide selection to end of slide
whole_slide.MoveEnd wdParagraph, 2
With whole_doc.Find
.Text = whole_slide
.ClearFormatting
.Replacement.Text = Chr(13) & Chr(13) & slidenum & " : " & staticTC & Chr(11) & static_next_line & Chr(11) & "C2N03 " & slidenum & " : " & Chr(11) & "C2N03" & Chr(32) & Chr(32) & slide_s1
.Execute Replace:=wdReplaceAll
End With
ElseIf Len(slide_s1) <> 0 And Len(slide_s2) <> 0 Then
'truncate line breaks at end of second sentence
slide_s2 = Replace(slide_s2, Chr(13), "")
slide_s2 = Left$(slide_s2, Len(slide_s2) - 1)
'replace text and move whole_slide selection to end of slide
whole_slide.MoveEnd wdParagraph, 3
With whole_doc.Find
.Text = whole_slide
.ClearFormatting
.Replacement.Text = Chr(13) & Chr(13) & slidenum & " : " & staticTC & Chr(11) & static_next_line & Chr(11) & "C2N03 " & slidenum & " : " & Chr(11) & "C2N03" & Chr(32) & Chr(32) & slide_s1 & "C2N03 " & slide_s2
.Execute Replace:=wdReplaceAll
End With
End If
End If
'Loop
End Sub
Do more with
Sub RemoveParaOrLineBreaks()
Dim staticTC As String
staticTC = "--:--:--:--,--:--:--:--,10"
Dim static_next_line As String
static_next_line = "80 80 80"
Dim Found As Boolean
Dim boolvar As Boolean
Dim firstsel As Boolean
Dim tpar As Variant
Dim parnum As Variant
Dim slide_s1 As String
Dim slide_s2 As String
slide_s1 = ""
slide_s2 = ""
Dim parasel As String
Dim new_replace As String
Dim vararray() As String
Dim newsel As Range
Dim whole_slide As Range
tpar = ActiveDocument.Paragraphs.count
boolvar = True
firstsel = True
Found = False
slide_s1 = ""
slide_s2 = ""
'Set whole_slide = Selection.Range
'whole_slide.WholeStory
'Set whole_slide = ActiveDocument.Content
Set slidenum = Selection.Range
slidenum.WholeStory
Set whole_doc = Selection.Range
whole_doc.WholeStory
'Do Until boolvar = False
'if this is the first time we're doing program, eval the first section
If firstsel = True Then
'find the first pattern of text: 4 digits followed by a space followed by a colon followed by a line break
parnum = 0
Set whole_slide = ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(14).Range.Start, End:=ActiveDocument.Paragraphs(tpar).Range.End)
MsgBox whole_slide
With whole_slide.Find
.ClearFormatting
.Execute FindText:="^#^#^#^#" & Chr(32) & ":" & Chr(13), Forward:=True, _
Format:=False, Wrap:=wdFindStop
'if we find it, tell us what we found and set found to true
If .Found = True Then
whole_slide.Find.Execute FindText:="^#^#^#^#"
slidenum = whole_slide
continue = True
Found = True
firstsel = False
MsgBox slidenum
MsgBox whole_slide
End If
End With
'if found is still not true, find the second pattern: 4 digits, followed by a letter, followed by a colon followed by a line break
If Found = False Then
With whole_slide.Find
.ClearFormatting
.Execute FindText:="^#^#^#^#^$" & Chr(32) & ":" & Chr(13), Forward:=True, _
Format:=False, Wrap:=wdFindStop
'if we find it, tell us what we found and set found to true. Also, parse found data and set slidenum to actual slide num
If .Found = True Then
whole_slide.Find.Execute FindText:="^#^#^#^#^$"
slidenum = whole_slide
continue = True
Found = True
firstsel = False
'MsgBox slidenum
End If
End With
End If
'if this is not the first time running the program
Else
'MsgBox whole_slide
'parnum = ActiveDocument.Range(0, whole_slide.Paragraphs(1).Range.End).Paragraphs.count
parnum = 13
Set whole_slide = ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(parnum).Range.Start, End:=ActiveDocument.Paragraphs(tpar).Range.End)
MsgBox whole_slide
With whole_slide.Find
.ClearFormatting
.Execute FindText:="^#^#^#^#" & Chr(32) & ":" & Chr(13), Forward:=True, _
Format:=False, Wrap:=wdFindStop
'if we find it, tell us what we found and set found to true
If .Found = True Then
whole_slide.Find.Execute FindText:="^#^#^#^#"
slidenum = whole_slide
continue = True
Found = True
MsgBox whole_slide
'parnum = ActiveDocument.Range(0, whole_slide.Paragraphs(1).Range.End).Paragraphs.count
MsgBox parnum
MsgBox tpar
' MsgBox slidenum
End If
End With
'if found is still not true, find the second pattern: 4 digits, followed by a letter, followed by a colon followed by a line break
If Found = False Then
With whole_slide.Find
.ClearFormatting
.Execute FindText:="^#^#^#^#^$" & Chr(32) & ":" & Chr(13), Forward:=True, _
Format:=False, Wrap:=wdFindStop
'if we find it, tell us what we found and set found to true. Also, parse found data and set slidenum to actual slide num
If .Found = True Then
wholse_slide.Find.Execute FindText:="^#^#^#^#^$"
slidenum = whole_slide
continue = True
Found = True
'MsgBox slidenum
End If
End With
End If
End If
If Found = False Then
Exit Sub
End If
If (continue = True And boolvar = True) Then
'Assign sentence after slide number to slide_s1 var
slide_s1 = whole_slide.Next(Unit:=wdSentence, count:=1)
'Assign second sentence to slide_s2 var
slide_s2 = whole_slide.Next(Unit:=wdSentence, count:=2)
'Check if slide_s2 winds up being part of the next slide. If so, set it to null.
If (slide_s2 Like "*####*" = True) Then
slide_s2 = ""
End If
'Decide if slide has one or two sentences
If Len(slide_s1) <> 0 And Len(slide_s2) < 1 Then
'replace text and move whole_slide selection to end of slide
whole_slide.MoveEnd wdParagraph, 2
With whole_doc.Find
.Text = whole_slide
.ClearFormatting
.Replacement.Text = Chr(13) & Chr(13) & slidenum & " : " & staticTC & Chr(11) & static_next_line & Chr(11) & "C2N03 " & slidenum & " : " & Chr(11) & "C2N03" & Chr(32) & Chr(32) & slide_s1
.Execute Replace:=wdReplaceAll
End With
ElseIf Len(slide_s1) <> 0 And Len(slide_s2) <> 0 Then
'truncate line breaks at end of second sentence
slide_s2 = Replace(slide_s2, Chr(13), "")
slide_s2 = Left$(slide_s2, Len(slide_s2) - 1)
'replace text and move whole_slide selection to end of slide
whole_slide.MoveEnd wdParagraph, 3
With whole_doc.Find
.Text = whole_slide
.ClearFormatting
.Replacement.Text = Chr(13) & Chr(13) & slidenum & " : " & staticTC & Chr(11) & static_next_line & Chr(11) & "C2N03 " & slidenum & " : " & Chr(11) & "C2N03" & Chr(32) & Chr(32) & slide_s1 & "C2N03 " & slide_s2
.Execute Replace:=wdReplaceAll
End With
End If
End If
'Loop
End Sub
Premium Content
You need an Expert Office subscription to comment.Start Free Trial