VBA Macro to extract strings from word doc - vba

i have a word document containing several strings. These strings have the first part always the same, for example ABC_001, ABC_002, ABC_003. I need to search for "ABC_" substring in the doc, extract all the occurences ("ABC_001", "ABC_002", "ABC_003") and copy them in an Excel sheet.
Anyone can help?
Thanks in advance.

You can reference the VBScript Regular Expressions 5.5 and regex them.
Have a look at http://www.macrostash.com/2011/10/08/simple-regular-expression-tutorial-for-excel-vba/
and http://txt2re.com/
and some of VBA multiple matches within one string using regular expressions execute method
EDIT:
Actually it is probably easier to go to data and "Get external data" choose de-limiter and import, either manually or record a macro to get a feeling for the vba structure.
This should get you all the entrys in seperate cells, then go over them with a MID to get the part you need

Related

Outlook VBA to search Email Subject for specific string format and copy to clipboard

I need to write a VBA that searches the subject of the highlighted EMail for a specific format of a string (is a reference number of a case).
The format is as follows:
3 capital letters / 1 or 2 numbers / 3 or 4 numbers / 2 numbers
e.g. ARK/5/1128/19 or RUB/11/548/19.
As soon as found to be copied into clipboard as this is a part of a longer procedure that needs to enter this ref no to a field.
This is part of a procedure that archives emails to public folders.
This code will assist to find the ref no easier and copy into clipboard so the user can paste it in the search box.
expect that string such as ABC/10/123/19 or DEF/4/1254/18 will be found and copied into cilpboard.
You can use regular expressions to evaluate the condition, whether the subject contains the string that corresponds to the pattern. Take a look at the following articles for more information on regular expressions:
VBA RegEx: How to Evaluate and Use “Regular Expressions”
How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops

Remove repeated adjacent words in a word document

word document may contain repeated adjacent words. can there be a vba macro code to retain single occurrence, and delete the repeat.
eg,
He is is doing well.
should change to
He is doing well.
Help would be much appreciated.
I can't try it because office.live.com doesn't seem to support wildcards, but you can try this:
In Find and Replace > Replace > check Use wildcards and in the Find what: enter "(<*>) <\1>" and click Find Next to see if that matches the two words. If it does, enter "\1" in Replace with: and click Replace All to see if everything works as expected. If it does, you can Record Macro of those steps and check the generated code.
The above expression should also find repeating numbers like a123 a123. If you don't want that, you can try this expression in the Find what:
(<[A-Za-z]{1,}>) \1[!A-Za-z]
from http://www.louiseharnbyproofreader.com/blog-the-proofreaders-parlour/proofreading-in-word-one-of-my-favourite-findreplace-strings

How to add formatted text to a word document in VBA

How can I take just a substring of text (but formatted, so it will keep it bold/italic/in a table) from one Word document and add it to another in VBA?
You might be better off copying the whole think, paste it in the new document and do some string replacements.

VB: how can i copy a word next to the one that i have found?

so, i am creating a program in VB that opem the html of a webpage, and searching the page code for a word like "youtube.com/watch?", so i want to know how i can copy in a variable the word next to the one that i looking for.
Here is an example what i am looking for:
https://www.youtube.com/watch?v=NwYv-f65P6w
so lets say that this is what i found on the page and that is what i want to copy "v=NwYv-f65P6w" the problem is that the "youtube.com/watch?" is always the same but the next is different for any video. So how can i copy it?
use regular expression to extract specific text pattern, in vb.net is so easy
you only need is to learn how to develop you’re own pattern.
something like this. (http://).+(?v=) this patter extract any text that’s start with http:// and contains any char and contains the text ?v=
lookup in google for some RegEx Patterns

Find and Replace a lot of abbreviated text with expanded form and other text

I have multiple lists of items in Excel that are in an abbreviated form and I want to set up a macro that will automatically go through the list and replace their abbreviated form with a regular name that also includes characters so I can just run a delineated Text to Columns function in Excel that will allow me to view and sort them properly. For example:
It1
It2
It3
It4
to
Red*Category 1*Item One
Red*Category 2*Item Two
Blue*Category 1*Item Three
Green*Category 2*Item Four
All I need is a simple find and replace for each individual item and I know that I will have to create that from scratch, but each list will have the same items/categories so I don't know the best way to go about it. I am wondering if I should make one long macro in Excel listing each individual find/replace or if it's possible to do something like create an XML file with a
<find>It1</find>
<replace>Red*Category 1*Item One</replace>
and just have a macro that references it? My goal is to build one file then have a macro I can use on each list.
For the moment assuming colours are determined by font, and and using the approach here then with a lookup table as shown the results for the sample data can be achieved with the following formula (copied down to suit):
=VLOOKUP(B1,$K$1:$M$23,2,0)&"*Category "&RIGHT(A1,1)&"*Item "&VLOOKUP(VALUE(RIGHT(A1,1)),$K$1:$M$23,3,0)