Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2017, 06:34 AM
saltire1963 saltire1963 is offline Windows 10 Office 2016
Novice
List part of multiple hyperlinks in .txt file
 
Join Date: Aug 2017
Posts: 2
saltire1963 is on a distinguished road
Default


I'm trying to list the multiple hyperlinks in a Word 2016 document in a .txt file. To be more specific, I'm trying to list the 36th character from the left to the 75th character of each hyperlink. The code below is close, because I did have it working earlier, but for some reason I must have changed something without realizing it. Anyone help pls?

Code:
Dim fso As FileSystemObject ' Declare a FileSystemObject.
Dim stream As TextStream ' Declare a TextStream.
Sub ListHyperlinks()
    
    Dim i As Integer
    Dim Rng As Range
    Dim strMid As String


    Set fso = New FileSystemObject ' Create a FileSystemObject.
    Set stream = fso.CreateTextFile("C:\Test1.txt", True)  

    Application.ScreenUpdating = False
    
    With ActiveDocument
        For i = .Hyperlinks.Count To 1 Step -1
            With .Hyperlinks(i)
                Set Rng = .Range
                strMid = Mid(Rng, 36, 75)
                stream.WriteLine (strMid)
            End With
        Next
    End With
    
    ' Close the file.
    stream.Close

    Application.ScreenUpdating = True
    
End Sub
I should add: when I step through the code above I get Rng = "" and srtMid = "" , the rectangle shape has now taken the place of the text I used to get
Reply With Quote
  #2  
Old 08-07-2017, 10:44 PM
macropod's Avatar
macropod macropod is offline List part of multiple hyperlinks in .txt file Windows 7 64bit List part of multiple hyperlinks in .txt file Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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:
Code:
Sub ListHyperlinks()
Dim i As Long, strOut As String, f As Long
Const StrFlOut As String = "C:\Test1.txt"
With ActiveDocument
  For i = 1 To .Hyperlinks.Count
    strOut = strOut & Mid(.Hyperlinks(i).Address, 36, 75) & vbCr
  Next
End With
f = FreeFile()
Open StrFlOut For Output As #f
Print #f, strOut
Close #f
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-15-2017, 07:51 PM
saltire1963 saltire1963 is offline Windows 10 Office 2016
Novice
List part of multiple hyperlinks in .txt file
 
Join Date: Aug 2017
Posts: 2
saltire1963 is on a distinguished road
Default

Paul, sorry for late reply. I modified your suggestion to the code below and it worked a treat, many thanks.

Code:
Dim fso As FileSystemObject ' Declare a FileSystemObject.
Dim stream As TextStream ' Declare a TextStream.
Sub Demo()
    
    Dim i As Long, Rng As Range
    Dim strMid As String

    Set fso = New FileSystemObject ' Create a FileSystemObject.
    Set stream = fso.CreateTextFile("C\Test1.txt", True)  ' Create a TextStream.
    
    Application.ScreenUpdating = False
    
    With ActiveDocument
        For i = .Hyperlinks.Count To 1 Step -1
            strMid = Mid(.Hyperlinks(i).Address, 36, 75) '& vbCr
            stream.WriteLine (strMid)
        Next
    End With
    
    ' Close the file.
    stream.Close

    Application.ScreenUpdating = True
    
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
List part of multiple hyperlinks in .txt file Creating a list of Hyperlinks in PPT deck Desiderata PowerPoint 5 06-16-2016 02:37 AM
List part of multiple hyperlinks in .txt file Inserting Only Part of File Name in Word ClaireLivings Word 1 04-14-2016 08:08 AM
List part of multiple hyperlinks in .txt file Multiple part presentation - how to present only a subset of slides + a conclusion ? dchabaut PowerPoint 3 04-07-2015 10:16 AM
List part of multiple hyperlinks in .txt file Copying a part of a docx file as a separate file officeboy09 Word 6 09-26-2014 05:15 PM
Multiple sharepoint list pst file vik__ Outlook 0 10-30-2010 02:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:13 AM.


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