Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-02-2023, 03:17 AM
RobiNew RobiNew is offline Replace a hard return with a dash in the text of a footnote Windows 10 Replace a hard return with a dash in the text of a footnote Office 2016
Competent Performer
Replace a hard return with a dash in the text of a footnote
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default Replace a hard return with a dash in the text of a footnote


I devised this macro to replace a hard return with a dash in the text of a footnote. Sometimes it works correctly, but sometimes it gives an error as if it tried to replace also footnote ending paragraphs. Any idea? Thanks!
Code:
Sub ReplRefNrWithinFootnote()
'Replaces with dash paragraph mark in the text of a footnote
Set parRng = ActiveDocument.StoryRanges(wdFootnotesStory)
    With parRng.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Wrap = wdFindStop
      .Format = False
      .MatchWildcards = True
      .Text = (Chr(13)) & "([!^02])" 'avoid ref. numbers
      .Execute
    While .Execute
      parRng.Text = Replace(parRng.Text, Chr(13), " " & Chr(150) & " ")
    Wend
    End With
End Sub
Reply With Quote
  #2  
Old 11-02-2023, 08:11 AM
vivka vivka is offline Replace a hard return with a dash in the text of a footnote Windows 7 64bit Replace a hard return with a dash in the text of a footnote Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, RobiNew! Try this:
Code:
Sub ReplRefNrWithinFootnote()
'Replaces with dash paragraph mark in the text of a footnote

Set parRng = ActiveDocument.StoryRanges(wdFootnotesStory)

On Error Resume Next
    With parRng.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Wrap = wdFindStop
      .Format = False
      .MatchWildcards = False
      .text = "^p" 
      While .Execute And parRng.End < ActiveDocument.StoryRanges(wdFootnotesStory).End
        parRng.text = Replace(parRng.text, Chr(13), " " & Chr(150) & " ")
        parRng.Collapse wdCollapseEnd
      Wend
    End With
End Sub
Reply With Quote
  #3  
Old 11-02-2023, 08:43 AM
RobiNew RobiNew is offline Replace a hard return with a dash in the text of a footnote Windows 10 Replace a hard return with a dash in the text of a footnote Office 2016
Competent Performer
Replace a hard return with a dash in the text of a footnote
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Thanks a lot, Vivka! This one seems to work without exception.
Reply With Quote
  #4  
Old 11-02-2023, 09:22 AM
vivka vivka is offline Replace a hard return with a dash in the text of a footnote Windows 7 64bit Replace a hard return with a dash in the text of a footnote Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

See you next time, RobiNew!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for Find/replace to remove space before Hard Return AlfredStreich Word VBA 4 01-23-2020 03:59 PM
Replace a hard return with a dash in the text of a footnote Find / Replace hard Carriage Return with Line break. GreenBoy Word 2 03-11-2018 02:32 AM
curly quotes after em-dash or hard space btorrance Word 0 06-07-2013 07:39 AM
Hard return renders upper case clafond Word 2 01-07-2013 12:26 PM
Hard page return? markg2 Outlook 0 09-11-2012 08:49 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:04 PM.


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