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

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.

Related

Mapping Keyboard Shortcuts in Word (vba) KeyBindings.Add KeyCategory: = wdKeyCategoryCommand, Command: = "..."

Good day.
Someone has a list of the commands that can be assigned a keyboard shortcut using the function:
KeyBindings.Add KeyCategory: = wdKeyCategoryCommand, Command: = "..."
I want to assign a shortcut to decreasing French indentation, but I only see the command for its increase: Command: = "HangingIndent"
Thank you. Greetings.
Choose Developer>Macros. Change the Macros in dropdown to Word commands. The complete list of available command names is displayed.
If you need to set specific indentation amounts, you'll have to write a simple macro instead of relying on Word's preset indentation values.
But it's probably better to avoid VBA altogether. Instead of relying on local formatting (which a Word command or macro would do), create a typestyle with your preferred indentation and apply that to the text. That's a better practice in Word and easy to update later if you change your mind about the amount of indentation.
The problem is precisely that, that the command related to the decrease of the French indentation does not appear in the list of Word commands. What I need to know is what the said command is called. After a lot of thinking I found a command to list all the keyboard shortcuts in the active document: Application.Run MacroName: =" CommandList" and this allowed me to find what I'm looking for: RemoveHangingIndent

How can I find a word with a new line in the VBA editor using find and replace?

I would like to go through and find all of the "End" statements in my code but skipping all of the "End x" statements like "End If", "End Sub", "End function", etc.--Just the pure "End". My thought was to use pattern matching, but I am unsure of how to do that.
I already tried using "End\n" and "End[\n]".
Does anyone know how to search for words that end in new lines?
The "find" function in the VBA editor does not support this kind of parameter/functionality.
You will have to manually step through the results and skip the ones you don't want to skip, or manually modify the "End" instances you don't want to catch, then search & replace, and finally restore all the End instances back to what you want.
Apologies for answering so long after the question was asked, but thought this information would help future readers as this question is still being actively found.
#TylerH is right that the specific search requested by the user cannot be performed in the VBE Find tool. For information, when "Use Pattern Matching" is selected the VBE Find tool supports use of:
? - single character
* - zero or more characters (on the same line)
# - single digit (0 to 9)
[charlist] - any single character in charlist
[!charlist] - any single character not in charlist
... where charlist can be a range of characters (eg [A-Z]) but must be in order (eg [Z-A] is not valid), it can also include multiple ranges of characters (eg [A-BD-E] matches A, B, D or E). Also to match any of ?, * or # then enclose them in square brackets (eg [*] matches an asterisk).
This means the VBE Find tool performs very similarly (perhaps identically ... but I can't provide assurances, VB and VBA not being the same language) to the VB Like operator, for which documentation is here
The alternative (which will perform the specific search in the question) is to use the 'Find Text' tool in the VBE Add-In MZ-Tools - though note MZ-Tools is a paid-for tool ... please note I am NOT in any way associated with MZ-Tools or it's author. The search text to use in MZ-Tools for the specific search requested in the question is: end\r?$

How to find and replace mixing format text in MS-Word or using 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.

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!!!

Macro for adding spaces between merged words in Microsoft Word

Today I had to edit a terrible text in Microsoft Word that have many paragraphs where all words are merged and text was impossible to read, nightmare :)
So, I thought, maybe there is a solution to this?
I have this idea: 1) I go through text (or paragraph) placing cursor
between words which should be separated (i.e. loremipsum should become lorem ipsum).
2) macro remember all occasions when I placed cursor
3) macro inserts necessary spaces between words
But inserting a space when I place cursor also can be good.
Any suggestions?
Thanks!
User939536, welcome to SO. Before you build a full-fledged Add-In to Word, a good chunk of your functionality is already there.
If you go to Word Options->Proofing->Autocorrect Options (your version may have a different method), you can see the list of words to automatically replace with other words. You can put your most commonly combined words here and let Word do the work for you.
The other route of course is to build an Add-In that will:
Have a database of commonly replaced words (probably a text file that's read on startup)
A search function to search the document
An interface to present the user with the choice to Replace or Skip.