Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-25-2018, 09:23 AM
rabauck rabauck is offline Macro which finds hyperlinks and replaces them as footnotes Windows 10 Macro which finds hyperlinks and replaces them as footnotes Office 2016
Novice
Macro which finds hyperlinks and replaces them as footnotes
 
Join Date: Jul 2018
Posts: 5
rabauck is on a distinguished road
Default Macro which finds hyperlinks and replaces them as footnotes

Hey there,

I have a lot of Word documents with a few hundred pages. They all contain hyperlinks but I want them to be footnotes.



I was wondering if there is a macro, that is searching for hyperlinks and deletes them and puts the anchor texts as footnotes.

Thank you!

Last edited by rabauck; 10-26-2018 at 08:29 AM.
Reply With Quote
  #2  
Old 10-25-2018, 01:34 PM
macropod's Avatar
macropod macropod is offline Macro which finds hyperlinks and replaces them as footnotes Windows 7 64bit Macro which finds hyperlinks and replaces them as footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try the following macro:
Code:
Sub HLnk2FtNt()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String
Dim wdDoc As Document, h As Long, Rng As Range
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, _
      AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      For h = .Hyperlinks.Count To 1 Step -1
        With .Hyperlinks(h)
          Set Rng = .Range
          With Rng
            .Collapse wdCollapseEnd
            .Footnotes.Add Rng
            .End = .End + 1
          End With
          Rng.Footnotes(1).Range.FormattedText = .Range.FormattedText
          .Range.Text = vbNullString
        End With
      Next
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-26-2018, 01:35 AM
rabauck rabauck is offline Macro which finds hyperlinks and replaces them as footnotes Windows 10 Macro which finds hyperlinks and replaces them as footnotes Office 2016
Novice
Macro which finds hyperlinks and replaces them as footnotes
 
Join Date: Jul 2018
Posts: 5
rabauck is on a distinguished road
Default

I receive the following error message:
Run-time error '429': ActiveX component can't create object

When Debugged, it points to this line:
Code:
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
Any thoughts?
Reply With Quote
  #4  
Old 10-26-2018, 04:02 AM
macropod's Avatar
macropod macropod is offline Macro which finds hyperlinks and replaces them as footnotes Windows 7 64bit Macro which finds hyperlinks and replaces them as footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I suggest re-starting your PC and, if that fails, repairing the Office installation (via Windows Control Panel > Programs > Programs & Features > Microsoft Office (version) > Change > Repair).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 10-26-2018, 06:58 AM
rabauck rabauck is offline Macro which finds hyperlinks and replaces them as footnotes Mac OS X Macro which finds hyperlinks and replaces them as footnotes Office 2016
Novice
Macro which finds hyperlinks and replaces them as footnotes
 
Join Date: Jul 2018
Posts: 5
rabauck is on a distinguished road
Default

I still get the error. Maybe the point is that I use Mac OS. I read that Mac doesn't support the Dictionary object. Is this possible?
Reply With Quote
  #6  
Old 10-26-2018, 12:49 PM
macropod's Avatar
macropod macropod is offline Macro which finds hyperlinks and replaces them as footnotes Windows 7 64bit Macro which finds hyperlinks and replaces them as footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by rabauck View Post
Maybe the point is that I use Mac OS.
Indeed. And had you had a correct user profile when you posted the question, I wouldn't have bothered developing that code...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 10-26-2018, 01:28 PM
rabauck rabauck is offline Macro which finds hyperlinks and replaces them as footnotes Mac OS X Macro which finds hyperlinks and replaces them as footnotes Office 2016
Novice
Macro which finds hyperlinks and replaces them as footnotes
 
Join Date: Jul 2018
Posts: 5
rabauck is on a distinguished road
Default

I'm sorry for making thinks complicated and bothering for you. I didn't notice that I must have accidentally selected the wrong OS.

Is there still a way to get this kind of macro for mac? Or is there a variable I can use in the code below instead of "hello"? I found this code by gmayor on another thread.

Code:
Sub Hyperlink2Footnote()
Dim oRng As Range
Dim strText As String
Dim lngIndex As Long
  Set oRng = ActiveDocument.Range
  lngIndex = 1
  With oRng.Find
    While .Execute(FindText:="hello", _
                   MatchWildcards:=True, _
                   ReplaceWith:="\1")
      ActiveDocument.Footnotes.Add oRng, CStr(lngIndex), oRng.Text
      lngIndex = lngIndex + 1
      oRng.Text = vbNullString
      oRng.Collapse 0
    Wend
  End With
lbl_Exit:
  Set oRng = Nothing
  Exit Sub
End Sub
Thanks a lot!
Reply With Quote
  #8  
Old 10-26-2018, 01:33 PM
macropod's Avatar
macropod macropod is offline Macro which finds hyperlinks and replaces them as footnotes Windows 7 64bit Macro which finds hyperlinks and replaces them as footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Graham's code won't help. In any event, most of the code I posted will work on a Mac; just not the code related to looping through a folder & opening documents.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 10-26-2018, 01:38 PM
rabauck rabauck is offline Macro which finds hyperlinks and replaces them as footnotes Mac OS X Macro which finds hyperlinks and replaces them as footnotes Office 2016
Novice
Macro which finds hyperlinks and replaces them as footnotes
 
Join Date: Jul 2018
Posts: 5
rabauck is on a distinguished road
Default

Is there a code for mac which is doing the same? Or any other alternative?
Reply With Quote
  #10  
Old 10-26-2018, 02:00 PM
macropod's Avatar
macropod macropod is offline Macro which finds hyperlinks and replaces them as footnotes Windows 7 64bit Macro which finds hyperlinks and replaces them as footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Probably, but I don't use a Mac.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 10-08-2022, 11:37 AM
asteer asteer is offline Macro which finds hyperlinks and replaces them as footnotes Windows 10 Macro which finds hyperlinks and replaces them as footnotes Office 2016
Novice
 
Join Date: Oct 2022
Posts: 1
asteer is on a distinguished road
Default macro does not do anything

I have tried to run this macro - it just sits there - nothing happens - I'm using office 365 - word - have saved the document as doc instead of docx - I don't need it to go through folders - just want it to do one file with 500 plus hyperlinks which I'd like converted to footnotes

see example
In the 2018 Europe Write the Docs conference, Predrag Mandic demonstrated the ...

what I want to get is :

In the 2018 Europe Write the Docs conference, Predrag Mandic [1]
demonstrated the ...
________
[1] https://www.youtube.com/watch?v=oW7rWJ2xNZU

with Word consecutively numbering the footnotes and placing them at the bottom of the page

Please help
Reply With Quote
  #12  
Old 10-21-2022, 03:55 PM
macropod's Avatar
macropod macropod is offline Macro which finds hyperlinks and replaces them as footnotes Windows 10 Macro which finds hyperlinks and replaces them as footnotes Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The code in post #2 works as described. Unlike your requirements, though, it deletes the hyperlink's 'click' text. You can preserve that by changing:
Code:
.Range.Text = vbNullString
to:
Code:
.Range.FieldsUnlink
For just the active document, you could use:
Code:
Sub HLnk2FtNt()
Application.ScreenUpdating = False
Dim h As Long, Rng As Range
With ActiveDocument
  For h = .Hyperlinks.Count To 1 Step -1
    With .Hyperlinks(h)
      Set Rng = .Range
      With Rng
        .Collapse wdCollapseEnd
        .Footnotes.Add Rng
        .End = .End + 1
      End With
      Rng.Footnotes(1).Range.FormattedText = .Range.FormattedText
      .Range.Fields.Unlink
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
hyperlink, macro, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro which finds hyperlinks and replaces them as footnotes Word macro for selecting text and putting it in footnotes mdhg Word VBA 20 03-06-2024 08:07 AM
Macro which finds hyperlinks and replaces them as footnotes Is there a macro to convert superscripted endnotes to active footnotes? mediadesign Word VBA 4 08-20-2018 03:20 PM
creating manuscript w/footnotes from separate documents containing chapters with footnotes-word 2010 Dottie Publisher 0 02-19-2017 03:18 PM
Macro which finds hyperlinks and replaces them as footnotes How can I create a macro to shift the content of all subsequent footnotes up one position? Atfon Word VBA 4 03-29-2016 05:51 AM
Macro which finds hyperlinks and replaces them as footnotes Word doesn't jumps tothe next lane when finds the dash sign!!!! why? Jamal NUMAN Word 3 04-10-2011 02:49 PM

Other Forums: Access Forums

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