Results 1 to 20 of 29

Thread: delete all styles but to keep the font, bold etc. format

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Yes Frosty, thank your for helping
    after that thing with the commas, the next problem emerged
    seems to be in an infinite loop
    I'm stopping the macro after 1 minute running and no result, pressing ctrl + pause break, and when the macro stops, it highlights the line possibly problematic, and it its the line '.execute' inside the block 'With rngResult.Find'.

    I'm gonna put the piece of block and write a comment (STOPS IN THIS LINE) to make it more clear

    Function StripStyleKeepFormatting(ByRef sty As Style, _
        ByRef doc As Document)
        Dim rngToSearch As Range
        Dim rngResult As Range
        Dim f As Font
    Set rngToSearch = doc.Range
        Set rngResult = rngToSearch.Duplicate
    Do
        With rngResult.Find
            .ClearFormatting
            .Style = sty
            .Text = ""
            .Forward = True
            .Wrap = wdFindStop
            .Execute                  'STOPS IN THIS LINE 
        End With
        If Not rngResult.Find.Found Then Exit Do
        Set f = rngResult.Font.Duplicate
        With rngResult
            .Font.Reset
            .Font = f
            .MoveStart wdWord
            .End = rngToSearch.End
        End With
        Set f = Nothing
        Loop Until Not rngResult.Find.Found
    End Function
    Last edited by Aussiebear; 04-21-2023 at 11:47 PM. Reason: Adjusted the code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •