PDA

View Full Version : [SOLVED:] Delete Line Breaks, Bold Text



Rishek
05-26-2017, 05:54 AM
Hi!

I'm using the following macro to delete parenthetical statements in a document:


Sub DelParen()
ActiveDocument.Content.Find.Execute _
FindText:="\(*\)", _
MatchWildcards:=True, _
ReplaceWith:="", _
Replace:=wdReplaceAll

End Sub

I would also like to delete the line breaks and any bold text. How would I best do this? Thanks!

gmaxey
05-26-2017, 09:46 AM
Sub DelParen()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "\(*\)"
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
Set oRng = ActiveDocument.Range
.Text = Chr(11)
.Replacement.Text = " "
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
Set oRng = ActiveDocument.Range
.Text = ""
.Font.Bold = True
.Replacement.Text = ""
.Format = True
.Execute Replace:=wdReplaceAll
Set oRng = ActiveDocument.Range
End With
End Sub

Rishek
05-28-2017, 11:49 AM
Thanks! This works very well and I can edit it pretty easily.

I think I've been using your macro to alphabetize comma delimited lists:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim arrItems() As String
arrItems = Split(Selection.Text, ",")
WordBasic.SortArray arrItems
Selection.Text = Join(arrItems, ",")
lbl_Exit:
Exit Sub
End Sub

I've encountered a sort of odd issue: it keeps taking the first item in the list and putting it at the end, e.g.

Bananas, Apples, Carrots, Dill Pickles, Eels, Grapes, Figs becomes: Apples, Carrots, Dill Pickles, Eels, Figs
, Grapes,Bananas (with the odd spacing at the end).

Any thoughts?

mdmackillop
05-28-2017, 12:33 PM
Extra spaces

arrItems = Split(Replace(Selection.Text, " ", ""), ",")

Rishek
05-28-2017, 01:32 PM
Thanks. Also had to alter


Selection.Text = Join(arrItems, ",")

to



Selection.Text = Join(arrItems, ", ")

Now it works well with the list, but it deletes the space in "Dill Pickles."

gmaxey
05-28-2017, 02:11 PM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim arrItems() As String
arrItems = Split(Selection.Text, ", ")
WordBasic.SortArray arrItems
Selection.Text = Join(arrItems, ", ")
lbl_Exit:
Exit Sub
End Sub

Rishek
05-28-2017, 06:25 PM
Great, thanks. Just have to be careful not to select the line break!