Как выполнить массовую замену ссылок, вставляемых в слова в ячейках Excel

7141
Karolinger

У меня огромный список слов, на которые есть ссылки. Все URL имеют текст, который повторяется. Я хочу массово заменить этот текст другим. Прямо сейчас «Заменить все» выполняет поиск только между словами, а не через встроенные гиперссылки за словами.

Пожалуйста помоги. Благодарю.

1

1 ответ на вопрос

2
Moses

The only way to do this is with a Macro:

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 

The ReplaceHyperlinkURL code must be placed in a VBA code module. From a spreadsheet, Press Alt+F11 to open the VBA Editor. Then select Insert - Module from the menu. Copy the code and paste it into the module. Then save the module.

In order to run the procedure, create a macro that contains following line and run the macro in Excel. Be sure to replace the FindText with the portion of the address you want to find and ReplaceText with the text you want to replace it with.

Call ReplaceHyperlinkURL("FindText", "ReplaceText")

Source

Я застрял в части макроса. Я не знаю, как создать макрос и запустить его. Как это сделать? Karolinger 10 лет назад 0
@Karolinger [Создание или удаление макроса - Служба поддержки Microsoft Office] (https://office.microsoft.com/en-us/excel-help/create-or-delete-a-macro-HP010342374.aspx) Moses 10 лет назад 1
Святой Моисей, @ Моисей. Вы спасли мою жизнь! Большое спасибо, чувак! Karolinger 10 лет назад 0
@Karolinger Рад, что я мог помочь :) Moses 10 лет назад 1