Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-01-2015, 10:08 AM
martinlest martinlest is offline Trying to create a macro to batch edit hyperlinks Windows 7 64bit Trying to create a macro to batch edit hyperlinks Office 2007
Advanced Beginner
Trying to create a macro to batch edit hyperlinks
 
Join Date: Jan 2011
Location: U.K. Hampshire
Posts: 37
martinlest is on a distinguished road
Default Trying to create a macro to batch edit hyperlinks

Hi. I am no VBA expert, so have had to rely on what I have found by Googling. But I am still getting errors. Can anyone kindly help?



Macros are enabled and the file saved with an xlsm extension. I first created a new module with the script A, below.

Then I created my macro, using a second module window (Alt+F11) which after saving looks like text B: but when I run it I get
'Compile error. Invalid Outside Procedure'

Can anyone advise what is wrong? Many thanks!

The original is here (and I replied, but it's an old thread so am probably not going to get answers by this stage):

http://superuser.com/questions/65735...in-excel-cells

Martin

A:

Public Sub ReplaceHyperlinkURL(FindString As String, ReplaceString As String) Dim LinkURL, PreStr, PostStr, NewURL As String Dim FindPos, ReplaceLen, URLLen As Integer Dim MyDoc As Worksheet Dim MyCell As Range On Error GoTo ErrHandler Set MyDoc = ActiveSheet For Each MyCell In MyDoc.UsedRange If MyCell.Hyperlinks.Count > 0 Then LinkURL = MyCell(1).Hyperlinks(1).Address FindPos = InStr(1, LinkURL, FindString) If FindPos > 0 Then 'If FindString is found ReplaceLen = Len(FindString) URLLen = Len(LinkURL) PreStr = Mid(LinkURL, 1, FindPos - 1) PostStr = Mid(LinkURL, FindPos + ReplaceLen, URLLen) NewURL = PreStr & ReplaceString & PostStr MyCell(1).Hyperlinks(1).Address = NewURL 'Change the URL End If End If Next MyCell Exit Sub ErrHandler: MsgBox ("ReplaceHyperlinkURL error") End Sub

B:


Call ReplaceHyperlinkURL("W:\", "E:\My Documents\") Sub ReplaceHyperlinkURL()

End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch edit mail merge macros? kbash Word 0 04-30-2014 08:32 AM
Trying to create a macro to batch edit hyperlinks Batch create Word documents cdfj Word VBA 6 11-07-2012 01:03 PM
Trying to create a macro to batch edit hyperlinks Batch Edit Links tosti PowerPoint 5 01-31-2012 12:51 PM
Using hyperlinks to create interactive menus hongkongphooey PowerPoint 0 01-25-2011 07:30 AM
Create Hyperlinks from Word to specific location in PDF sukanyae Word 0 02-25-2010 04:08 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:21 AM.


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