Link to home
Start Free TrialLog in
Avatar of netian
netian

asked on

Searching for a url and replace it with some text using Macro

Hi,
I am trying to search for a url and replace it with some text using Macro in word document.
Can some one please help me ?

Thanks,
Mobi.
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

What problem are you having?

Do Ctrl+H and put the URL in the Find box, and the new text in the Replace box.

Find: https://www.experts-exchange.com/questions/25498725/Searching-for-a-url-and-replace-it-with-some-text-using-Macro.html?cid=1763

Replace: Some text

Then click Replace or Replace All


Avatar of netian
netian

ASKER

Hi Graham,
I want to do it through macro. It should be an automated task when the word document loads up.

Thanks,
Mubashir.
This needs to go in the ThisDocument module of the document's template.
Private Sub Document_Open()
    With ActiveDocument.Range.Find
        .Text = "http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_25498725.html?cid=1763"
        .Replacement.Text = "Some text"
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Open in new window

Avatar of netian

ASKER

Thanks Graham. But i want a regular expression that can search the text for any URL and then replace it.

Thanks,
Mobi.
SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of netian

ASKER

Hi Graham,
They are simple text like www.somedomain.com, and not hyperlinks in word document, i would like to use a regular expression that parses the whole text of the document and then just replaces the url with some other text.

Thanks,
Mobi.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial