Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 10-25-2018, 09:23 AM
rabauck rabauck is offline Windows 10 Office 2016
Novice
 
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 Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,468
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
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
[MS MVP - Word]
Reply With Quote
  #3  
Old 10-26-2018, 01:35 AM
rabauck rabauck is offline Windows 10 Office 2016
Novice
 
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 Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,468
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
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
[MS MVP - Word]
Reply With Quote
  #5  
Old 10-26-2018, 06:58 AM
rabauck rabauck is offline Mac OS X Office 2016
Novice
 
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 Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,468
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
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
[MS MVP - Word]
Reply With Quote
  #7  
Old 10-26-2018, 01:28 PM
rabauck rabauck is offline Mac OS X Office 2016
Novice
 
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 Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,468
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
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
[MS MVP - Word]
Reply With Quote
  #9  
Old 10-26-2018, 01:38 PM
rabauck rabauck is offline Mac OS X Office 2016
Novice
 
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 Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,468
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Probably, but I don't use a Mac.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Tags
hyperlink, macro, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a macro to convert superscripted endnotes to active footnotes? mediadesign Word VBA 4 08-20-2018 03:20 PM
Word macro for selecting text and putting it in footnotes mdhg Word VBA 11 08-03-2017 08:42 PM
creating manuscript w/footnotes from separate documents containing chapters with footnotes-word 2010 Dottie Publisher 0 02-19-2017 03:18 PM
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
Word doesn't jumps tothe next lane when finds the dash sign!!!! why? Jamal NUMAN Word 3 04-10-2011 02:49 PM


All times are GMT -7. The time now is 11:42 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft