nyconfidential
New Member
- Joined
- Jul 22, 2015
- Messages
- 49
- Office Version
- 365
- 2016
Hi all, I have a relative simple sub that I am running to change the name of a reference in a cell(we are replacing a worksheet, I'm looking for references to the old worksheet and replacing the name). It works perfectly when I run it from the immediate window, but if I call it from a button click event on a form, it does not work(no error, it just doesn't replace the old worksheet reference). Can anyone tell me what I am doing wrong? Thanks in advance.
Code:
Public Sub UpdateReferences(wkbCopyPath As String)
On Error GoTo errHandler
Application.StatusBar = True
Dim wkbCopy As String
Dim wrkSht As Worksheet
wkbCopy = Dir(wkbCopyPath)
For Each wrkSht In ActiveWorkbook.Worksheets
Application.StatusBar = "Updating references on sheet " & wrkSht.Index & " of " & Sheets.Count
'Replace references to workbook you are copying from in other worksheets
Cells.Replace What:=shtName & "_OLD", Replacement:=shtName, _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:= _
False, ReplaceFormat:=False
Next wrkSht
CleanUpNamedRanges wkbCopy, shtName & "_OLD"
Exit_UpdateReferences:
Application.StatusBar = False
Exit Sub
errHandler:
Call ErrorHandlerFunction("UpdateReferences")
Resume Exit_UpdateReferences
End Sub