How to bulk replace links that are embed to words in Excel cells
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")
Related videos on Youtube
Amjad Khalil
Updated on September 18, 2022Comments
-
Amjad Khalil over 1 year
I do have this form and i have another component that use vue2-dropzone to upload files. When choosing the files the $store state uploads will be updated. My issue is when am submiting the form so the FormData not sending the files. formdata.append not working. I do check under networks and i can see that formdata is equal to {}. What i did for wrong please.
<form class="outer-repeater" @submit.prevent="submitTask"> <div data-repeater-list="outer-group" class="outer"> <div data-repeater-item class="outer"> <div class="form-group row mb-4"> <label for="taskname" class="col-form-label col-lg-2">Task Name</label> <div class="col-lg-10"> <input id="taskname" name="taskname" type="text" class="form-control" placeholder="Enter Task Name..." v-model="task.title" /> </div> </div> <div class="form-group row mb-4"> <label class="col-form-label col-lg-2">Task Description</label> <div class="col-lg-10"> <ckeditor :editor="editor" v-model="task.description"></ckeditor> </div> </div> <div class="form-group row mb-4"> <label class="col-form-label col-lg-2">Task Date</label> <div class="col-lg-10"> <date-picker v-model="task.daterange" range append-to-body lang="en" confirm></date-picker> </div> </div> <div class="inner-repeater mb-4"> <div class="inner form-group mb-0 row"> <label class="col-form-label col-lg-2">Add Team Member</label> <div class="inner col-lg-10 ml-md-auto" > <div class="mb-3 row align-items-center"> <div class="col-md-12"> <multiselect v-model="task.teamMember" label="name" :options="options" :multiple="true" :taggable="true"></multiselect> </div> </div> </div> </div> </div> <div class="form-group row mb-4"> <label for="taskbudget" class="col-form-label col-lg-2">Budget</label> <div class="col-lg-10"> <input id="taskbudget" name="taskbudget" type="text" placeholder="Enter Task Budget..." class="form-control" v-model="task.budget" /> </div> </div> <div class="form-group row mb-4"> <label for="taskbudget" class="col-form-label col-lg-2">Ladda up</label> <div class="col-lg-10"> <uploads/> </div> </div> </div> </div> <div class="row justify-content-end"> <div class="col-lg-10"> <button type="submit" class="btn btn-primary" >Create Task</button> </div> </div> </form> methods: { files(){ return this.$store.state.uploads.uploads }, submitTask() { let formData = new FormData(); for (var i = 0; i < this.files.length; i++) { let file = this.files[i]; formData.append('files[' + i + ']', file); console.log(file) } formData.append('task',this.task) axios.post('http://test.local/wp-json/mytestapi/submitTodo', { formData, headers: { 'Content-Type': 'multipart/form-data;boundary=' + Math.random().toString().substr(2), } }).then(res => { console.log(res.data) }).catch(res => { console.log(res) }) }, },
-
Parth Parekh over 3 yearsplease share data variable with default value...
-
-
Karolinger over 10 yearsI'm in stuck the macro part. I don't know how to create the macro and run it. How can do this?
-
Admin over 10 years
-
Karolinger over 10 yearsHoly Moses, @Moses. You saved my life! Thank you very much, man!
-
Admin over 10 years@Karolinger Glad I could help :)