Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-08-2025, 04:21 PM
chrisjj chrisjj is offline Word 2003  Sub InsertHyperlinksFromClipboard macro Windows 7 64bit Word 2003  Sub InsertHyperlinksFromClipboard macro Office 97-2003
Competent Performer
Word 2003  Sub InsertHyperlinksFromClipboard macro
 
Join Date: Aug 2025
Posts: 120
chrisjj is on a distinguished road
Default Word 2003 Sub InsertHyperlinksFromClipboard macro


You might find this handy.

Needs Microsoft Forms 2.0 Object Library.

Code:
Sub InsertHyperlinksFromClipboard_OnePerLine_Corrected()
    Dim clipboard As New DataObject
    Dim clipboardText As String
    Dim lines() As String
    Dim i As Long
    Dim lineText As String
    Dim doc As Document
    Dim para As Paragraph
    Dim insertPos As Range
    
    On Error GoTo ErrorHandler

    ' Get clipboard text
    clipboard.GetFromClipboard
    clipboardText = clipboard.GetText

    lines = Split(clipboardText, vbCrLf)
    Set doc = ActiveDocument

    ' Start insertion at current selection
    Set insertPos = Selection.Range
    insertPos.Collapse Direction:=wdCollapseStart

    For i = 0 To UBound(lines)
        lineText = Trim(lines(i))
        If Len(lineText) > 0 Then
            ' Insert a new paragraph at the insertion point
            insertPos.InsertParagraphBefore
            ' Move insertion point to the new paragraph
            insertPos.MoveStart Unit:=wdParagraph, Count:=-1
            insertPos.Collapse Direction:=wdCollapseStart
            
            ' Insert hyperlink into this paragraph
            doc.Hyperlinks.Add Anchor:=insertPos, Address:=lineText, TextToDisplay:=lineText
            
            ' Move insertion point to end of paragraph for next insertion
            insertPos.Collapse Direction:=wdCollapseEnd
        End If
    Next i

    MsgBox "Inserted hyperlinks, one per paragraph.", vbInformation
    Exit Sub

ErrorHandler:
    MsgBox "Error accessing clipboard. Make sure Microsoft Forms 2.0 Object Library is enabled.", vbCritical
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2003  Sub InsertHyperlinksFromClipboard macro Old macro in Word 2003 Do no work in Word2010 Michael007 Word VBA 1 09-06-2015 06:14 PM
Convert Word 2007 macro to work in Word 2003 Kamaflage Word VBA 1 02-25-2015 11:40 PM
Word 2003  Sub InsertHyperlinksFromClipboard macro Word 2003 Macro problem running in Word 2010 norwood Word VBA 2 02-03-2014 06:49 PM
[Word 2003] Macro's and a UserForm xanuex Word VBA 0 10-19-2009 05:42 AM
Problem with AutoClose macro and Word 2003 cholo Word VBA 0 07-08-2009 05:48 AM

Other Forums: Access Forums

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