Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 11-22-2021, 01:40 PM
RMittelman RMittelman is offline Search & Replace using Document.Content Doesn't Include Footers Windows 10 Search & Replace using Document.Content Doesn't Include Footers Office 2016
Novice
Search & Replace using Document.Content Doesn't Include Footers
 
Join Date: Dec 2010
Posts: 19
RMittelman is on a distinguished road
Default

Thanks GMayor. Great example. In the meantime, I've been working on this and came up with the following code:

Code:
'---------------------------------------------------------------------------------------
' Procedure         : replace_quotes_with_smart_quotes
' Author            : RMittelman@gmail.com
'
' Purpose           : Replaces plain apostrophes & quotes with Word smart quotes
'
' History           :   11/14/2021  Initial version
'                       11/20/2021  Replaced Regex code with Word Find code
'
' Returns           : Boolean indicating success or failure.
'
' Notes             :
'
'---------------------------------------------------------------------------------------
'
Private Function replace_quotes_with_smart_quotes() As Boolean

    Dim myStoryRange    As Object
    Dim arFind          As Variant
    Dim arReplace       As Variant
    Dim i               As Integer
    
    replace_quotes_with_smart_quotes = False
    On Error GoTo error_handler
    
    arFind = Array(" '", "'", " """, """")
    arReplace = Array(Chr$(145), Chr$(146), Chr$(147), Chr$(148))
    
    For Each myStoryRange In WordDoc.StoryRanges
        With myStoryRange.Find
            
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .ClearFormatting
            
            For i = 0 To UBound(arFind)
                .Text = arFind(i)
                .Replacement.Text = arReplace(i)
                .Replacement.ClearFormatting
                .Replacement.Highlight = False
                .Execute Replace:=wdReplaceAll
            Next
            
        End With
    Next myStoryRange

    replace_quotes_with_smart_quotes = True
    
exit_handler:
    
    On Error Resume Next
    Set myStoryRange = Nothing
    Exit Function
    
error_handler:
    
    m_LastError = Err.Description
    If MsgBoxEx(Err.Description, vbRetryCancel + vbExclamation + vbDefaultButton2, "Error " & Err.Number, , , vbRed, , "&Debug", "&Exit") = vbRetry Then
        Stop
        Resume
    End If
    
    replace_quotes_with_smart_quotes = False
    Resume exit_handler

End Function
Somewhat similar to what you did. Not familiar enough with story ranges to understand what you did, or why some of the types require you to do the replacing again.

Looping through the story ranges in a for each loop seems to work, but now I'm concerned that it may fail under certain circumstances.

I'd appreciate knowing what's going on in your code, because I'm using my technique to replace other things in the document also.

Access rich text is totally confusing to Word, so I can't simply place my rich text paragraphs from access storage into a Word document. So I'm using plain text with codes like "<e>", "<se>" & "<ce>" in my paragraph text and then popping them into the Word document and replacing them with {Enter}, {Shift-Enter} & {Ctrl-Enter} Word codes. This seems to work, but now I'm concerned that I'm not using story types and text frames and such.

Thanks again...
Reply With Quote
 

Tags
regex, vba, word 16



Similar Threads
Thread Thread Starter Forum Replies Last Post
Search &amp; Replace using Document.Content Doesn't Include Footers Help to include header and footer in string search code which i already have. branko Word VBA 1 03-28-2017 11:50 PM
Search &amp; Replace using Document.Content Doesn't Include Footers Need some vba code to search a word document an replace it if len = 3 Belleke Word VBA 3 10-24-2016 01:00 AM
Table of content to not include TOC as first section!? neuroscientist911 Word 4 11-19-2014 07:55 AM
Windows Search Does Not Include Outlook jkingston Outlook 0 07-20-2014 08:43 AM
Looking for Windows Search app with ability to search by content gopher_everett Office 1 02-28-2013 09:23 PM

Other Forums: Access Forums

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