How to find and replace mixing format text in MS-Word or using VBA - vba

Here is an example of what I want. Suppose a text:
paper[1], some texts[2], paper[3]
Here is the expected result ==>
paper[1], some texts[2], paper[3]
That is, I want to replace all "paper[1]" with "paper[1]" and similarly, replace "paper[3]" with "paper[3]" but keep the texts[2] unchanged.
I have noticed that word can not search the mixing format text, e.g., I can not find the text "paper[3]". So I may need the VBA to achieve this. Any ideas? Thanks!

You don't even need VBA for that! A wildcard Find/Replace can be used, where:
Find = paper\[[13]\]
Replace = ^&
and the replacement font is set to 'not superscript'. If you really want a macro, record the above.

Related

PDFBOX - WordUtils.wrap - need to display bold and non-bolded text on same line

I am a newbie to pdfbox AND java - trying to replicate a pdf letter with logos formatting etc. I need to use mixed font (bold) within a sentence. Presently appending paragraph string, using WordUtils.wrap, then begin.Text , etc. to parse and display (drawString has strikethrough cannot select this - I did find info for multi font using it). As field values will vary in text and length, I cannot simply search on, split and change font to display. Unable to use tags to do this (OMG I've tried everything I can think of!), but hoping there is a way to use a single char identifier for beginning of bold and another for end of bold??? One issue is that no guarantee the identifiers would end up on the same line of the paragraph. UGH. Everything else is perfect, EXCEPT the text I need to bold. Does anyone have any suggestions?? I am required to use pdfbox to accomplish this - cannot use Itext. Help please! Thank you!!
SOLVED - I figured it out. Thank you for your suggestions!
I did not want to use positioning, needing to keep it as simple as possible. We'll eventually need to implement hundreds of letters. I Am using Utils.wrap strictly as a line parser, not formatting, so that is cool.
Using 2 identifiers - 3 checks -
1) both on the same line,
2) beginning bold on one line, and
3) end bold on another line.
Using split string by " " and checks equal to identifiers. Formatting is perfect. Going forward may need to modify, if for some crazy reason identifiers are contained in letter text.
It works for the 1st roll-out. Thanks again - your help is much appreciated!!!

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

MS Word, how to change formatting of entire paragraphs automatically in whole document?

I have a 20-page word document punctuated with descriptive notes throughout, like this:
3 Input Data Requirements
Some requirement text.
NOTE: This is a descriptive note about the requirement, which is the paragraph that I would like to use find-and-replace or a VBA script to select automatically and change the formatting to italicized. The notes invariably end in a carriage-return: ΒΆ.
If it was just a text document, not MS-Word, I would just use a regex in a code editor like sublime to wrap it with <I>...</I> or something along those lines.
Preferably, is there a way to do this in Word's "advanced" find-and-replace feature? Or if not, what's the best way to do it in VBA?
I've tried using a search string like this in find-and-replace: NOTE: *[a-z0-9,. A-Z)(-]{1,255}^l but the line-break part doesn't seem to work, and the 255 char max isn't enough for many of the paragraphs.
EDIT: Another slightly important detail: The doc is automatically generated from another piece of software as a .RTF, which I promptly converted to .docx.
Attempt #2: Use Notepad++ to find and replace using regex. Remove quotes.
Find: "( NOTE: .*?)\r"
Replace with: " \i \1 \i0 \r "
//OLD
Sure is. No VBA or fancy tricks needed.
CTRL + H to bring up the replace dialog.
Click "More".
Select "Font" in the drop down menu called "Format".
Click italics.
Enter find and replace text as the same thing. Make sure you set this up right so that you don't accidentally replace substrings (e.g. goal to replace all " test " with " nice ", testing -> niceing).
Should work. If you need to alter entire paragraphs, consistently, then you probably should have used the styles on those paragraphs to begin with. That way, you can change all of them at once by updating the style itself.
You can use Advance Find, yes. Find Next and then Replace makes the selection Italic.

Check if string follows format

Basically I have created an acronym finding macro and it works well except it includes all of our reference numbers. Now unfortunately changing the search parameters won't work as many acronyms include both letters and numbers.
My idea was to compare the string, once found, and if it is in the reference number format e.g.
LetterNumberNumberLetterLetterNumberNumberNumberNumber
I will simply not include it.
I'm certain there must be a simple way of doing this and me not being able to locate it is a case of not knowing what to search for but anyway thank you in advance for the help.
Use LIKE:
'//LetterNumberNumberLetterLetterNumberNumberNumberNumber
if ucase$("A12BC3456") like "[A-Z][0-9][0-9][A-Z][A-Z][0-9][0-9][0-9][0-9]" then
msgbox "is ref no."

VBA Macro to extract strings from word doc

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