Re: how do I get word and paragraph based on character position?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I am not following what you mean by the Subject title.

"based on character position"????

And what do you mean it contains the character 2043. Do you mean a literal
string "2043"?

We do not have enough information to suggest the "best" solution, but here is
a possibility. Say you are in your index - plain text I assume. You put
your cursor in a index "title" - say, Gnocchi.

What do you want to do? From your post, it seems you want to start looking
through the document for instances of "Gnocchi", and make a decision Yes or
No, as to whether that found instance is where you want to be. this will do
that.

Dim strIn As String
Dim r As Range
Dim response

Selection.Expand unit:=wdParagraph
strIn = Left(Selection.Text, Len(Selection.Text) - 1)

Set r = ActiveDocument.Range
With r.Find
Do While .Execute(FindText:=strIn, Forward:=True) = True
r.Select
response = MsgBox("Is this the one?", vbYesNo)
If response = vbNo Then
r.Collapse wdCollapseEnd
Else
Exit Sub
End If
Loop
End With

What it does:

1. expands the Selection to the paragraph. This an assumption that may, or
may not, be correct. It could be adjusted. It is here so that you could put
the cursor in a line of multiple words, and get the whole line (or really,
paragraph)

2. sets a string variable to use as the search string - less the paragraph
mark

3. set a range variable for the document

4. search the range (the document content) for the search string

5. when found, select it. This moves the Selection (the cursor) to THAT
location.

6. display a message asking if this is where you want to be

7. if No, collapse the range and move on to the next found instance of the
search string

8. if Yes, Exit the procedure...as you have decided you are at the right
place.

Now, the code could certainly be adjusted to do something once you "are
there"...but you do not state exactly what that is.

Fil wrote:
Let say I want to know the word or the paragraph that contains the character
2043.
How do I call them?

--------------------------------
For the story I have a book of Italian cooking recipes (the absolute best
one that every italian grandma has on her shelves) in plain text that I am
trying to put in a nice format. The problem is that it is ~ 3000 pages long.
Luckily when I pasted the content of the txt file (a friend of mine sent me)
into word, I noticed that all formatting information hadn't been lost. I have
one recipe per page and paragraphs were preserved.
Based on what I see in the index, I want to link the index to the body of
the document. When the index will be properly linked to the text I will be
able to create back the proper structure of the document: chapter, sub
chapter, ... with a dedicated formatting for each of them.

Right now I am going through the index, grabing the title of each section
(basically I get rid of the spaces and page number), looking at all the
occurences of this title in the body of the occument and will select among
them the one which is at the beginning of a paragraph, hoping hard there's
only one that match this criterion. Once I found this occurence I will link
the item of my index to this occurence.
--------------------------------

Thx

--
Message posted via http://www.officekb.com

.



Relevant Pages

  • Re: Searching by Unicode codes
    ... What character are you searching for? ... What is its hex number? ... search string ^U0xnnnn, for example - no luck there, and similarly no luck ... Are there any other settings ...
    (microsoft.public.word.application.errors)
  • Re: [Dialog] Cracking Richard
    ... in the database, ... Some people use special formats for sigs or even set sigs to be ... I can see in the hex editor that the control character that precedes ... search string contains regular expressions ...
    (news.software.readers)
  • Re: Find/Replace in TStringList loses lots of data
    ... Nth file character (where N is the search string length) against all ... If it is in the search string it jumps ... Basically one sets up a 256 character array of byte values, ...
    (comp.lang.pascal.delphi.misc)
  • Re: Find & Replace Question
    ... Your statement "That extra character remains part of the ... search string, but you want to keep that character, so ... you mark it with round brackets to enable you to put back ...
    (microsoft.public.word.newusers)
  • Re: finding and deleting duplicated lines
    ... by character 013, which is the paragraph mark (ie, this expression matches ... In this case there is only one bracketed expression, ... > Would you mind explaining what the search string represents? ...
    (microsoft.public.word.docmanagement)