Hello, I have a long text with references inside brackets that I now want to convert into footnotes (in Word). To find the references easily, I have put a hidden @ immediately after the first bracket. I want to write a macro that finds the @, moves at right one character and from there searches for the ending bracket by highlighting the text between the brackets. Once this is made, it will be easy to program the rest. The part I don't know how to achieve is how to highlight the text between the brackets in order to cut it. Any ideas?
Last edited by Huldrich; Oct 29th, 2024 at 11:52 AM.
Dim example As String
Dim extractedText As String
example = "123456 sometext @[grab this] soke more text afterwards"
' first find the @ and take all the text to the right of it and the first bracket [
' + 2 is to not include the @[ in the extracted text value
extractedText = Mid(example, InStr(example, "@") + 2)
' now just keep the text to the left of the next bracket
extractedText = Left(extractedText, InStr(extractedText, "]") - 1)
Sheet1.Cells(5, 1).Value = "The found text is: " & extractedText
EDIT: Excel was used just to show the VBA to extract the text more easily display it
Teststring = "123456 sometext [@grab this] soke more text afterwards" (He mentioned the @ AFTER the first Bracket)
Pattern = \[@(.*)\]
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad