![]() |
#1
|
|||
|
|||
![]()
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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Batch edit mail merge macros? | kbash | Word | 0 | 04-30-2014 08:32 AM |
![]() |
cdfj | Word VBA | 6 | 11-07-2012 01:03 PM |
![]() |
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 |