Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-02-2023, 03:25 AM
gmayor's Avatar
gmayor gmayor is offline Change color of hyperlinks in multiple documents Windows 10 Change color of hyperlinks in multiple documents 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


Your sample documents have manual formatting in the form of pink shading that is at the root of the problem. I would also recommend that you put the code in an add-in template or the normal template rather than a document. The following will remove the formatting from the hyperlinks and adopt the hyperlink styles that are present in the documents.
Code:
Option Explicit

Sub UpdateDocuments3()
'Graham Mayor - https://www.gmayor.com - Last updated - 02 Aug 2023
Dim strFolder As String, strFile As String
Dim wdDoc As Document
Dim oLink As Hyperlink
    strFolder = BrowseForFolder("Select folder containing the documents to process")
    If strFolder = "" Then Exit Sub
    strFile = Dir(strFolder & "*.docx")
    While strFile <> ""
        Set wdDoc = Documents.Open(FileName:=strFolder & strFile, AddToRecentFiles:=False, Visible:=True)
        'Debug.Print strFile
        With wdDoc
            For Each oLink In .Hyperlinks
                oLink.Range.Select
                Selection.ClearFormatting
            Next oLink
            .Close SaveChanges:=True
        End With
        strFile = Dir()
    Wend
    Set wdDoc = Nothing
    MsgBox "finished.", vbOKOnly
End Sub
 
Private Function BrowseForFolder(Optional strTitle As String) As String
'Graham Mayor
'strTitle is the title of the dialog box
Dim fDialog As FileDialog
    On Error GoTo Err_Handler
    Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
    With fDialog
        .Title = strTitle
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then GoTo Err_Handler:
        BrowseForFolder = fDialog.SelectedItems.Item(1) & Chr(92)
    End With
lbl_Exit:
    Exit Function
Err_Handler:
    BrowseForFolder = vbNullString
    Resume lbl_Exit
End Function
__________________
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change color of hyperlinks in multiple documents VBA to change multiple change drop down font color and make bold bwhitlock Word VBA 1 08-08-2022 12:18 AM
Change color of hyperlinks in multiple documents How to change multiple hyperlinks in word 2019 Zakko Word 5 04-08-2019 08:04 PM
Change color of hyperlinks in multiple documents Removing Hyperlinks in Multiple Documents at Once Jude24Joy Word VBA 10 06-13-2017 05:38 AM
Change the color of multiple borders Jim Robison Excel 2 09-06-2016 11:08 AM
Change color of hyperlinks in multiple documents Change Multiple Documents from US to UK language swifty2010 Word 1 03-08-2011 02:00 PM

Other Forums: Access Forums

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


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