View Single Post
 
Old 12-22-2021, 11:29 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
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

That's not going to work ... as you have found. Try the following instead.



Code:
Sub UpdateDocuments()
Dim strInFolder As String, strOutFold As String, strFile As String
Dim wdDoc As Document
Dim hLink As Hyperlink
Dim sAddress As String, sDisplay As String, sTip As String

    Application.ScreenUpdating = False
    strInFolder = GetFolder
    If strInFolder = "" Then Exit Sub
    strFile = Dir(strInFolder & "\*.doc*", vbNormal)

    'Check for documents in the folder - exit if none found
    If strFile <> "" Then strOutFold = strInFolder & "\Output\"

    'Test for an existing outpfolder & create one if it doesn't already exist
    If Dir(strOutFold, vbDirectory) = "" Then MkDir strOutFold
    strFile = Dir(strInFolder & "\*.doc*", vbNormal)
    While strFile <> ""
        Set wdDoc = Documents.Open(FileName:=strInFolder & "\" & strFile, AddToRecentFiles:=False, ReadOnly:=True, Visible:=False)

        For Each hLink In wdDoc.Hyperlinks
            With hLink
                sAddress = .Address
                If InStr(1, LCase(sAddress), "www.yahoo.com") > 0 Then
                    .Target = Replace(LCase(.Target), "www.yahoo.com", "www.google.com")
                    .Address = Replace(LCase(.Address), "www.yahoo.com", "www.google.com")
                    .TextToDisplay = Replace(LCase(.TextToDisplay), "www.yahoo.com", "www.google.com")
                    .ScreenTip = "Click to search"
                End If
            End With
        Next hLink
    Next hLink

    'Save and close the document
    wdDoc.SaveAs FileName:=strOutFold & wdDoc.Name, AddToRecentFiles:=False
    wdDoc.Close
    strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
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