Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
ArthurN ArthurN is offline
external usenet poster
 
Posts: 15
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
DeanH DeanH is offline
external usenet poster
 
Posts: 1,862
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Pesach Shelnitz Pesach Shelnitz is offline
external usenet poster
 
Posts: 17
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
ArthurN ArthurN is offline
external usenet poster
 
Posts: 15
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
CyberTaz CyberTaz is offline
external usenet poster
 
Posts: 1,348
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
ArthurN ArthurN is offline
external usenet poster
 
Posts: 15
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
DeanH DeanH is offline
external usenet poster
 
Posts: 1,862
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Peter T. Daniels Peter T. Daniels is offline
external usenet poster
 
Posts: 3,215
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Pesach Shelnitz Pesach Shelnitz is offline
external usenet poster
 
Posts: 17
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
uppercase on beginning of every new line bevs Microsoft Word Help 6 November 12th 08 02:24 PM
Erase a line of text beginning with known word(s) jbly Microsoft Word Help 4 September 11th 08 01:38 PM
capitals at beginning of a line Fred Evans[_2_] New Users 2 August 12th 07 03:26 AM
symbols in the beginning of the line and at the beginning of theline in style news.microsoft.com New Users 3 April 11th 07 12:12 PM
How do I go to line below with cursor at the beginning. kd7ajh New Users 2 August 22nd 06 02:49 PM


All times are GMT +1. The time now is 10:38 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"