Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2016, 05:21 PM
gmaxey gmaxey is offline Reverse Bold macro Windows 7 32bit Reverse Bold macro Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default


Paul,

I don't' see a reason for it happening and it seems a first rate bug to me. The code is "finding" text and replacing that text with itself with a different font attribute. There is nothing it the code that I see that should cause bookmarks to shift to the left.

As I said, the code is clunky to begin with. Now it is even more clunky restoring the bookmarks :

Code:
Sub ReverseBoldIII()
Application.ScreenUpdating = False
Dim oRI As Range, oRng As Range
Dim oCol As New Collection
Dim oBM As Bookmark
Dim lngIndex As Long
Dim arrRng() As String
  For Each oBM In Selection.Range.Bookmarks
    oCol.Add oBM.Start & "|" & oBM.End
  Next
  Set oRng = Selection.Range.Duplicate
  Set oRI = Selection.Range.Duplicate
  With oRng.Find
    .Text = "*"
    .Font.Bold = False
    .MatchWildcards = True
    With .Replacement
      .Text = "^&"
      .Font.Bold = True
      .Font.DoubleStrikeThrough = True 'any unused font attribute
    End With
    .Execute Replace:=wdReplaceAll
   End With
   Set oRng = Selection.Range.Duplicate
   With oRng.Find
    .Text = "*"
    .Font.Bold = True
    .Font.DoubleStrikeThrough = False
    .MatchWildcards = True
    With .Replacement
      .Text = "^&"
      .Font.Bold = False
    End With
    .Execute Replace:=wdReplaceAll
   End With
   Set oRng = Selection.Range.Duplicate
   oRng.Select
   With oRng.Find
    .Text = "*"
    .Font.Bold = True
    .Font.DoubleStrikeThrough = True
    .MatchWildcards = True
    With .Replacement
      .Text = "^&"
      .Font.DoubleStrikeThrough = False
    End With
    .Execute Replace:=wdReplaceAll
   End With
   Set oRng = Selection.Range
   For lngIndex = 1 To oCol.Count
     Set oBM = oRI.Bookmarks(lngIndex)
     arrRng = Split(oCol.Item(lngIndex), "|")
     oBM.Start = arrRng(LBound(arrRng))
     oBM.End = arrRng(UBound(arrRng))
    Next
Application.ScreenUpdating = True
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Reverse Bold macro Macro to find and replace headings in bold and underline redzan Word VBA 4 02-13-2016 12:24 PM
Creating macro in 2007 to bold within quotes on the fly marymaryt Word VBA 5 06-01-2015 06:55 AM
Macro Needed to bold specific lines and Macro to turn into CSV anewteacher Word VBA 1 05-28-2014 03:59 PM
Macro to reverse a test string Jennifer Murphy Word VBA 5 01-16-2014 03:19 PM
Format Bold in one line makes all lines bold Nitte Word 2 02-07-2013 12:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:52 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft