F
frogman
Code work unless certain code is run then it messes up if the selected
text is in a bookmark and is part of a table
Sub Draft()
'Application.ScreenUpdating = False
Dim i As Integer
Dim strBookmarkName As String
Dim strTest As Variant
Application.ActiveWindow.ActivePane.View.ShowAll = True
'Find tables with blue italics text
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Font.Italic = True
.Font.Color = wdColorBlue
.Font.Hidden = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
'Loop through and find all tables and hide the tables
While Selection.Find.Found
'check to see if the table is inside a bookmark
On Error Resume Next
strBookmarkName = Selection.Bookmarks(1).Name
'if table is not inside a book mark unhide it
If strBookmarkName = "" Then
Selection.SelectRow
Selection.Font.Hidden = False
If Selection.Font.Color = wdColorBlue And
Selection.Font.Italic = True Then
Selection.Borders.Enable = True
End If
'if the selection is the last row of a table then hide the
return after it.
If Selection.Rows.Last.IsLast Then
Selection.Move unit:=wdParagraph, Count:=1
Selection.Paragraphs(1).Range.Select
Selection.Font.Hidden = False
End If
Else ' if the table is inside a bookmark check to see if the
bookmark is hidden
'if the bookmark is not hidden unhide the book mark
''** If
ActiveDocument.Bookmarks(strBookmarkName).Range.Font.Hidden = False
Then
Selection.SelectRow
Selection.Font.Hidden = False
If Selection.Font.Color = wdColorBlue And
Selection.Font.Italic = True Then
Selection.Borders.Enable = False
End If
'if the selection is the last row of a table then hide
the return after it.
If Selection.Rows.Last.IsLast Then
Selection.Move unit:=wdParagraph, Count:=1
Selection.Paragraphs(1).Range.Select
Selection.Font.Hidden = False
End If
strBookmarkName = ""
Else 'if the bookmark is hidden change the font color so
the search will skip this table
Selection.Font.Color = wdColorGold
strBookmarkName = ""
Selection.Find.Font.Color = wdColorBlue
End If
End If
Selection.HomeKey unit:=wdStory
Selection.Find.Execute
Wend
'Find all the nonbold red "["
Call FindBold("[", True, False)
'Find all the nonbold red "]"
Call FindBold("]", True, False)
'Find all the bold red "{"
Call FindBold("{", True, True)
'Find all the bold red "}"
Call FindBold("}", True, True)
'Find all the bold red "["
Call FindBold("[", True, True)
'Find all the bold red "]"
Call FindBold("]", True, True)
'change all the gold text back to blue so the final mode will work
again
Selection.Find.Replacement.ClearFormatting
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Font.Color = wdColorGold
.Replacement.Font.Color = wdColorBlue
End With
Selection.Find.Execute , Replace:=wdReplaceAll
Selection.Find.Replacement.ClearFormatting
Selection.Find.ClearFormatting
ActiveWindow.View.FieldShading = wdFieldShadingAlways
Application.ActiveWindow.ActivePane.View.ShowAll = False
Application.ActiveWindow.View.ShowHiddenText = False
Application.ScreenUpdating = True
End Sub
Function FindBold(strChar, blnHidden, blnBold)
Selection.HomeKey unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = strChar
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Font.Bold = blnBold
.Font.Color = wdColorRed
.Font.Hidden = blnHidden
.Replacement.Font.Hidden = Not blnHidden
End With
'Execute the find command
Selection.Find.Execute Replace:=wdReplaceAll, Format:=True
End Function
text is in a bookmark and is part of a table
Sub Draft()
'Application.ScreenUpdating = False
Dim i As Integer
Dim strBookmarkName As String
Dim strTest As Variant
Application.ActiveWindow.ActivePane.View.ShowAll = True
'Find tables with blue italics text
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Font.Italic = True
.Font.Color = wdColorBlue
.Font.Hidden = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
'Loop through and find all tables and hide the tables
While Selection.Find.Found
'check to see if the table is inside a bookmark
On Error Resume Next
strBookmarkName = Selection.Bookmarks(1).Name
'if table is not inside a book mark unhide it
If strBookmarkName = "" Then
Selection.SelectRow
Selection.Font.Hidden = False
If Selection.Font.Color = wdColorBlue And
Selection.Font.Italic = True Then
Selection.Borders.Enable = True
End If
'if the selection is the last row of a table then hide the
return after it.
If Selection.Rows.Last.IsLast Then
Selection.Move unit:=wdParagraph, Count:=1
Selection.Paragraphs(1).Range.Select
Selection.Font.Hidden = False
End If
Else ' if the table is inside a bookmark check to see if the
bookmark is hidden
'if the bookmark is not hidden unhide the book mark
''** If
ActiveDocument.Bookmarks(strBookmarkName).Range.Font.Hidden = False
Then
Selection.SelectRow
Selection.Font.Hidden = False
If Selection.Font.Color = wdColorBlue And
Selection.Font.Italic = True Then
Selection.Borders.Enable = False
End If
'if the selection is the last row of a table then hide
the return after it.
If Selection.Rows.Last.IsLast Then
Selection.Move unit:=wdParagraph, Count:=1
Selection.Paragraphs(1).Range.Select
Selection.Font.Hidden = False
End If
strBookmarkName = ""
Else 'if the bookmark is hidden change the font color so
the search will skip this table
Selection.Font.Color = wdColorGold
strBookmarkName = ""
Selection.Find.Font.Color = wdColorBlue
End If
End If
Selection.HomeKey unit:=wdStory
Selection.Find.Execute
Wend
'Find all the nonbold red "["
Call FindBold("[", True, False)
'Find all the nonbold red "]"
Call FindBold("]", True, False)
'Find all the bold red "{"
Call FindBold("{", True, True)
'Find all the bold red "}"
Call FindBold("}", True, True)
'Find all the bold red "["
Call FindBold("[", True, True)
'Find all the bold red "]"
Call FindBold("]", True, True)
'change all the gold text back to blue so the final mode will work
again
Selection.Find.Replacement.ClearFormatting
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Font.Color = wdColorGold
.Replacement.Font.Color = wdColorBlue
End With
Selection.Find.Execute , Replace:=wdReplaceAll
Selection.Find.Replacement.ClearFormatting
Selection.Find.ClearFormatting
ActiveWindow.View.FieldShading = wdFieldShadingAlways
Application.ActiveWindow.ActivePane.View.ShowAll = False
Application.ActiveWindow.View.ShowHiddenText = False
Application.ScreenUpdating = True
End Sub
Function FindBold(strChar, blnHidden, blnBold)
Selection.HomeKey unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = strChar
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Font.Bold = blnBold
.Font.Color = wdColorRed
.Font.Hidden = blnHidden
.Replacement.Font.Hidden = Not blnHidden
End With
'Execute the find command
Selection.Find.Execute Replace:=wdReplaceAll, Format:=True
End Function