Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 10-04-2018, 12:24 PM
gmaxey gmaxey is offline Macros from this Forum will not run. Windows 7 32bit Macros from this Forum will not run. Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,600
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default


Code:
Sub Delete_Underlines()
'A basic Word macro coded by Graham Mayor,
   'adapted by Greg Maxey, http://gregmaxey.com/word_tips.html, 10/4/2018
Dim oRng As Range
Dim oScope As Range
  Set oRng = Selection.Range
  Set oScope = oRng.Duplicate
  With oRng.Find
    .ClearFormatting
    .Font.Underline = wdUnderlineSingle
    .Replacement.ClearFormatting
    Do While .Execute()
      If oRng.InRange(oScope) Then
      If oRng.Hyperlinks.Count = 0 Then
        oRng.Select
        If MsgBox("Do you want to remove underline from this instance", vbYesNo, "Actio") = vbYes Then
          oRng.Font.Underline = wdUnderlineNone
        End If
        oRng.Collapse 0
      End If
      Else
        Exit Do
      End If
   Loop
  End With
lbl_Exit:
  Set oRng = Nothing
  Set oScope = Nothing
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #17  
Old 10-05-2018, 08:59 AM
Seatonian Seatonian is offline Macros from this Forum will not run. Windows 7 64bit Macros from this Forum will not run. Office 2010 64bit
Novice
Macros from this Forum will not run.
 
Join Date: Sep 2018
Posts: 7
Seatonian is on a distinguished road
Default

Hello Greg, Thank you for picking up the baton and running a bit further. I have been working on your latest Version, but need more time for solid progress. The "Stepping" mechanism is fine, but it will only delete single Underlines despite my attempt to add wdUnderlineThick and wdUnderlineDouble into the .Find section. I will work on it more, then contact you again if it won't work.


I'm afraid the MsgBox will have to go as it obscures the screen so I can't see which Underline is in focus. I seem to remember fixing something similar years ago. I'll try to find it and work on it some more and get in touch in a couple of days. Thank you again for all the trouble you have taken.
Robert.
Reply With Quote
  #18  
Old 10-05-2018, 10:38 PM
gmayor's Avatar
gmayor gmayor is offline Macros from this Forum will not run. Windows 10 Macros from this Forum will not run. Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will remove any type of underline. If the message box obscures the item drag it out of the way.

Code:
Sub Delete_Underlines()
' 'Graham Mayor - http://www.gmayor.com - Last updated - 06 Oct 2018
'
' Delete_Underlines Macro
' Will delete all underlines in Document except in Mail addresses (& hyperlinks ??)
Const strUline As String = "1|2|3|4|6|9|10|11|20|23|25|26|27|39|43|55"
Dim vUline As Variant
Dim oRng As Range
Dim oWord As Range
Dim i As Long
    vUline = Split(strUline, "|")
    For i = 0 To UBound(vUline)
        Set oRng = ActiveDocument.Range
        With oRng.Find
            .ClearFormatting
            .Font.Underline = CLng(vUline(i))
            .Replacement.ClearFormatting
            Do While .Execute()
                If oRng.Hyperlinks.Count = 0 Then
                    oRng.Select
                    If MsgBox("Do you want to remove underline from this instance", vbYesNo) = vbYes Then
                        oRng.Font.Underline = wdUnderlineNone
                    End If
                    oRng.Collapse 0
                End If
            Loop
        End With
    Next i
lbl_Exit:
    Set oRng = Nothing
    Set oWord = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #19  
Old 10-07-2018, 01:56 AM
Seatonian Seatonian is offline Macros from this Forum will not run. Windows 7 64bit Macros from this Forum will not run. Office 2010 64bit
Novice
Macros from this Forum will not run.
 
Join Date: Sep 2018
Posts: 7
Seatonian is on a distinguished road
Default

Thank you, Graham, for the definitive Underline Deletion Macro for all 17 Styles of Line. It works perfectly. I have spent several hours studying the sophisticated Code and learned much in the process. Brilliant ! I asked for a bicycle and got a Rolls Royce. Thank you for your patience.... and your genius.


My thanks to all other kind contributors for their generosity. Have a splendid day.
Reply With Quote
  #20  
Old 10-07-2018, 05:19 AM
gmaxey gmaxey is offline Macros from this Forum will not run. Windows 7 32bit Macros from this Forum will not run. Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,600
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

I was tinkering with something similar yesterday before my grandchildren blew in like a tempest. I wasn't taking it as far as Graham has (e.g., I was only interested in the three underline styles that you enumerated) but I did want the user to see apparent order in processing. Here I've combined Graham's work with a bit of my own.

Code:
Sub Delete_Underlines()
'Graham Mayor - http://www.gmayor.com - Last updated - 06 Oct 2018
'Adapted by y Greg Maxey, http://gregmaxey.com/word_tips.html, 10/7/2018
' Delete_Underlines Macro
' Will delete all underlines in Document except in Mail addresses (& hyperlinks ??)
Const strUline As String = "1|2|3|4|6|9|10|11|20|23|25|26|27|39|43|55"
Dim vUline As Variant
Dim oRng As Range
'Dim oWord As Range Deleted GKM
Dim i As Long
Dim lngCount As Long 'Added GKM
Dim arrRanges() As String 'Added GKM
  vUline = Split(strUline, "|")
  For i = 0 To UBound(vUline)
    Set oRng = ActiveDocument.Range
    With oRng.Find
      .ClearFormatting
      .Font.Underline = CLng(vUline(i))
      .Replacement.ClearFormatting
      Do While .Execute()
        If oRng.Hyperlinks.Count = 0 Then
          'Instead of processig here, just collect the affected ranges.
           ReDim Preserve arrRanges(lngCount)
           arrRanges(lngCount) = oRng.Start & "|" & oRng.End
           lngCount = lngCount + 1
           oRng.Collapse 0
        End If
     Loop
    End With
  Next i
  'Sort the affected ranges.
  WordBasic.SortArray arrRanges
  Set oRng = ActiveDocument.Range
  'Process the affected ranges in the order they occur.
  For i = 0 To UBound(arrRanges)
    oRng.Start = Split(arrRanges(i), "|")(0)
    oRng.End = Split(arrRanges(i), "|")(1)
    oRng.Select
    If MsgBox("Do you want to remove underline from this instance", vbYesNo) = vbYes Then
        oRng.Font.Underline = wdUnderlineNone
    End If

  Next i
lbl_Exit:
  Set oRng = Nothing
  'Set oWord = Nothing Deleted GKM
  Exit Sub
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
Is there a sub-Forum for Office for Mac? IvanH Office 1 02-20-2014 11:31 PM
Macros from this Forum will not run. MS Windows forum? Joan64 Office 2 07-01-2013 10:18 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:59 AM.


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