Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old Yesterday, 06:45 AM
RobiNew RobiNew is offline Find and select a passive URL string Windows 11 Find and select a passive URL string Office 2016
Competent Performer
Find and select a passive URL string
 
Join Date: Sep 2023
Posts: 214
RobiNew is on a distinguished road
Default Find and select a passive URL string

Hi, everybody! Can someone help? I'm trying to find and select the whole string of a passive URL. Here below my tentative code, which stops too soon.




Code:
Sub SelectNextURL()
    Dim rng As Range
    Dim startPos As Long
    Dim endPos As Long
    Dim doc As Document
    Dim urlPattern As String
    Dim found As Boolean
    
    Set doc = ActiveDocument
    
    'URLs starting with http or https
    urlPattern = "(https?://[^\s<>""']+)"
    
    ' Use the Find object
    Set rng = doc.Content
    With rng.Find
        .ClearFormatting
        .Text = ""
        .MatchWildcards = True
        ' Word wildcards: http[s]:// followed by any non-space characters
        .Text = "(http*)(://*)([! ^13^32^9^t<>'""]@)"
        found = .Execute
    End With
    
    If found Then
        rng.Select
        MsgBox "URL found and selected: " & rng.Text, vbInformation
    Else
        MsgBox "No URL found.", vbExclamation
    End If
End Sub

Last edited by macropod; Yesterday at 12:51 PM. Reason: Added code tags for code formatting
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find string, Replace with dot tab dhapp Word 5 03-27-2023 07:23 AM
Find and select all string of simlar pattern anon123 Word 4 04-20-2016 11:41 PM
How to find all string within string. PRA007 Word VBA 18 02-12-2016 08:11 PM
Find and select a passive URL string Why is this Find string not working TechEd Word VBA 5 07-05-2014 08:12 PM
Find and select a passive URL string Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM

Other Forums: Access Forums

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