Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Searching for a word at the beginning of the line
Hi,
I'm just beginning to study macro and got kinda lost. I'm looking for a word, say "glossary" and the beginning of the line and I want to apply style "H2" to each found word in the document. Hope some pro can help me here, thanks in advance, Arthur |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Searching for a word at the beginning of the line
You can do this with Find/Replace function, you don't need a macro.
DeanH "ArthurN" wrote: Hi, I'm just beginning to study macro and got kinda lost. I'm looking for a word, say "glossary" and the beginning of the line and I want to apply style "H2" to each found word in the document. Hope some pro can help me here, thanks in advance, Arthur |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Searching for a word at the beginning of the line
Hi Arthur,
As Dean pointed out, you can use Find/Replace to do this, but I'd like to add a few details that you might find helpful. You can find a word, say "glossary" at the beginning of a paragraph by searching for ^pglossary, but bear in mind that the search will select the carriage return at the end of the previous line along with the word that you want to find. Since you don't want to change the text, you must repeat the complete search string in Replace With. With your cursor in Replace With, click More, click Format, click Style, and select the style that you want to apply to the search string. Here's where the fact that the search selects the carriage return of the previous line becomes important. Since this carriage return is selected, the style will also be applied to it. If you select a character style, there is no problem, but if you select a paragraph style, the style will be applied to the previous paragraph along with the entire paragraph containing the word in your search. Also, after you run a Find/Replace with options selected on the expanded dialog box, you should run another Find/Replace with those options cleared. Otherwise, you might end up applying the style in all future Find/Replace operations. -- Hope this helps, Pesach Shelnitz "DeanH" wrote: You can do this with Find/Replace function, you don't need a macro. DeanH "ArthurN" wrote: Hi, I'm just beginning to study macro and got kinda lost. I'm looking for a word, say "glossary" and the beginning of the line and I want to apply style "H2" to each found word in the document. Hope some pro can help me here, thanks in advance, Arthur |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Searching for a word at the beginning of the line
Yes, the trouble is the carriage return is selected as well, I was wondering
if there's a code for the line beginning, similar to the one you can find in text editing programs supporting regular expressions. Unfortunately, find/replace tool isn't the answer for me, since I have to apply this kind of formating to over 200 documents for educational purposes and actually heading "glossary" is only one of them, there're similar headings such as "lesson", "script" as so on. |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Searching for a word at the beginning of the line
Coming at your query from a different direction than the other replies...
What exactly are you trying to accomplish? "H2" suggests a Heading Style which would be a *paragraph* style & wouldn't be applied to a single word of a paragraph that contains other text. Nor would it seem appropriate to apply the H2 style to every paragraph that contains the word. You may be having the difficulty because your objective -- at least as stated -- is illogical. If you could be more descriptive of what you are actually trying to achieve perhaps there are other options to consider. It might also be helpful to know what version of Word you're using. Regards |:) Bob Jones [MVP] Office:Mac On 6/29/09 7:11 AM, in article , "ArthurN" wrote: Hi, I'm just beginning to study macro and got kinda lost. I'm looking for a word, say "glossary" and the beginning of the line and I want to apply style "H2" to each found word in the document. Hope some pro can help me here, thanks in advance, Arthur |
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Searching for a word at the beginning of the line
I'm sorry for being vague.
So, I've got hundreds of documents carrying some basic formating, bold, cursive, different fonts. The structure of the documents, clear though: Glossary word 01 - definition word 02 - definition Story Here goes the complete story I want to accomplish the following. Write a macro that would select all "glossary", "story" words and apply H2 heading style (to clarify the structure of the document). Next, in the glossary section, I would like to select all words/phrases that start at the beginning of the line till "-" symbol and apply carachter style called, say "inline vocabulary'. (since I have a macro that would convert those word to an exercise for my students). Now, this seems to be too huge for my modest vba skill and I really hope somebody will give me a hand here. Thanx, Arthur |
#7
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Searching for a word at the beginning of the line
I have used the following Find syntax that finds all characters from the
start of a paragraph upto and including a colon ( character. I use it to select that text, then I apply a character style that applies the formatting I require. Find - [+0-9A-z&./,)( €“_-]{1,}\: Replace €“ nothing, character style Remember to turn Wildcards on. I also find est results by starting at bottom of document and search Up. Hope this helps with your macro. DeanH "ArthurN" wrote: I'm sorry for being vague. So, I've got hundreds of documents carrying some basic formating, bold, cursive, different fonts. The structure of the documents, clear though: Glossary word 01 - definition word 02 - definition Story Here goes the complete story I want to accomplish the following. Write a macro that would select all "glossary", "story" words and apply H2 heading style (to clarify the structure of the document). Next, in the glossary section, I would like to select all words/phrases that start at the beginning of the line till "-" symbol and apply carachter style called, say "inline vocabulary'. (since I have a macro that would convert those word to an exercise for my students). Now, this seems to be too huge for my modest vba skill and I really hope somebody will give me a hand here. Thanx, Arthur |
#8
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Searching for a word at the beginning of the line
You've made the task much simpler. It's a series of basic Find/Replace
actions, which it should be quite simple to chain into a looping macro (I don't do macros myself): 1. Find Glossary, Replace with Style "H2" (with the cursor in the Replace box, click More Format H2), Replace All 2. Do the same with Story in the Find box. 3. If there really is a space, hyphen, space before each definition (and nowhere else), then construct a Find expression using wildcards that will cover each vocabulary item, ending it with space, hyphen, space; and in the Replace box, make the Style (as above) "inline vocabulary," and click Replace All. On Jun 29, 10:37*am, ArthurN wrote: I'm sorry for being vague. So, I've got hundreds of documents carrying some basic formating, bold, cursive, different fonts. The structure of the documents, clear though: Glossary word 01 - definition word 02 - definition Story Here goes the complete story I want to accomplish the following. Write a macro that would select all "glossary", "story" words and apply H2 heading style (to clarify the structure of the document). Next, in the glossary section, I would like to select all words/phrases that start at the beginning of the line till "-" symbol and apply carachter style called, say "inline vocabulary'. (since I have a macro that would convert those word to an exercise for my students). Now, this seems to be too huge for my modest vba skill and I really hope somebody will give me a hand here. Thanx, Arthur |
#9
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Searching for a word at the beginning of the line
Hi Arthur,
You seem to be convinced that a macro is the best way to accomplish what you want. In that case, create a character style named "Inline Vocabulary" and try this macro. Sub FormatDoc() Dim myRange As Range Dim i As Long Dim pos As Integer Dim inGlossary As Boolean With ActiveDocument For i = 1 To .Paragraphs.Count If .Paragraphs(i).Range.Words(1) = "Glossary" Then inGlossary = True .Paragraphs(i).style = .Styles(wdStyleHeading2) ElseIf .Paragraphs(i).Range.Words(1) = "Story" Then inGlossary = False .Paragraphs(i).style = .Styles(wdStyleHeading2) ElseIf inGlossary = True Then Set myRange = .Paragraphs(i).Range pos = InStr(1, myRange.Text, _ "-", vbTextCompare) If pos 0 Then myRange.End = myRange.Start + pos - 2 myRange.style = .Styles("Inline Vocabulary") End If End If Next End With End Sub -- Hope this helps, Pesach Shelnitz |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
uppercase on beginning of every new line | Microsoft Word Help | |||
Erase a line of text beginning with known word(s) | Microsoft Word Help | |||
capitals at beginning of a line | New Users | |||
symbols in the beginning of the line and at the beginning of theline in style | New Users | |||
How do I go to line below with cursor at the beginning. | New Users |