Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #24  
Old 03-20-2024, 01:19 PM
Shelley Lou Shelley Lou is offline VBA IF Statement Help Windows 10 VBA IF Statement Help Office 2016
Expert
VBA IF Statement Help
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA IF Statement Help

Hi Greg, yes that has definitely worked, thank you so much. Thank you for suggesting I split the previous code into a few sections so I can identify any errors easily. I've run each section individually to see how they perform before updating the MainProcedure code with the various Calls and for some reason, the CompoundCRs code is changing spaces after periods at the end of sentences from two spaces to one space (our housestyle is two spaces). I can't see why this is happening though.

I've been trying to update the CompoundCRs code to include if there is a space or non-breaking space present but nothing has worked yet so I remembered what you said in an earlier post that sometimes its best to remove something and put it back in at the end, so I've added a find and replace in the CompoundCRs Code to remove any non-breaking spaces associated with the cross references and created a new Call to reinstate the non-breaking spaces at the end of the process.

I can't thank you enough for your help on this, it will really help me a lot when housestyling documents going forward.

Code:
Sub DPU_ReinstateNonBreakingSpaces_CRs()
Dim oRng As Range, fld As Field, sFind1 As String, arr() As String, i As Long
sFind1 = "[Aa]rticle [Aa]rticles [Aa]ppendix [Aa]ppendices [Cc]lause [Cc]lauses [Pp]aragraph [Pp]aragraphs [Pp]art [Pp]arts [Ss]chedule [Ss]chedules [Ss]ection [Ss]ections Act [Rr]egulation [Rr]egulations [Oo]rder [Rr]ule [Rr]rules"
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
    .Replacement.ClearFormatting
    .Format = False
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
arr = Split(sFind1, " ")
    For i = 0 To UBound(arr)
   .text = "(" & arr(i) & ") ([0-9.]{1,})"     'NBS for clause etc. references in the array
   .Replacement.text = "\1^s\2"
   .Execute Replace:=wdReplaceAll
    Next
    For Each fld In oRng.Fields                     'Spaces before auto cross-refs are NBS
            If fld.Type = wdFieldRef Then
                If Not fld.Result.Previous Is Nothing Then
                    Set oRng = fld.Result.Previous.Characters(1)
                    If oRng.text = Chr(32) Then oRng.text = Chr(160)
                End If
            End If
  Next
  End With
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA IF Statement Help IF Statement (again) teza2k06 Excel 8 02-11-2022 08:41 AM
Converting a Select statement in Excel to an update statement shabbaranks Excel Programming 5 10-31-2018 11:47 PM
VBA IF Statement Help Need a little help with an if statement cangelis Excel 2 04-08-2015 05:55 PM
VBA IF Statement Help If statement, may be? Tony Singh Excel 6 03-04-2015 12:52 PM
VBA IF Statement Help Need help with If, Then Statement Please cangelis Excel 4 01-03-2014 09:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:02 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