PDA

View Full Version : read character and current page



kon
11-14-2007, 01:32 PM
Hey Guys,
I'm trying to find solution for my problem. I'm pretty new to VBA, so I appreciate any suggestions :)

I've got this piece of code:


Sub FindStyle()

Dim sty As Style
Set sty = ActiveDocument.Styles("Tag")

Dim rng As Range
Set rng = ActiveDocument.Content

Dim txt As String

With rng.Find
.Text = ""
.Style = sty
.Execute
Do While .Found = True
MsgBox rng.Text
.Execute
Loop
End With

MsgBox txt

End Sub


Basically, I'm going through the entire content of my document to find the character style with the name "Tag". I would like to print out some piece of text, which is in front of the word.

E.g. This is my example text ..... Lets imagine, that I marked the word text. So it would be printed out "This is my example ". And I'm also trying to print out the current page of the match. Is that possible? Thanks a lot for you help.

Kon

fumei
11-14-2007, 02:43 PM
Since you can not seem to answer questions directly asked of you - in fact, ones rather close to the question you are asking here - I think I shall avoid getting further frustrated trying to ask other questions. As I do not get answers, it seems pointless.

Besides, I sure as heck do not want be further labeled, or is that libeled? Just kidding.

I am sure someone else will help you.

kon
11-15-2007, 12:05 PM
Sorry if you got the felling that I'm not responding to your questions, but finally solved the problem with the help of all of you. Thanks for that.

I put this question in a separate thread because I thing it's an other purpose - so it should be separated.

fumei
11-15-2007, 12:36 PM
Well I certainly agree that if it is a separate question, then it should be in a separate thread.

I would suggest you look at some FAQ on proper use of forums like this.

1. If you come up with your own solution to a question you posted, it is considered polite to post that solution. The point of these forums is to help others. Perhaps your solution may help others with a similar issue.

2. I did not get the "felling" - but I am sure you mean "feeling" - that you are not responding to questions. You are NOT responding to questions. It is not my feeling...it is a fact. You do not answer questions.

kon
11-18-2007, 02:52 AM
I mentioned in my last post what kind of way I took to solve my problem.

And again, sorry if you got the feeling, that I'm responding to your question. If I didn't,then it was for sure not on purpose! I guess we're all adults, so lets just stop this kind of conversation.

I'm still looking for a solution. So please help :)

TonyJollans
11-18-2007, 05:06 AM
On the one hand you say you've "solved the problem with the help of all of you" and on the other, "I'm still looking for a solution". What, exactly, is it that you still want?

lucas
11-18-2007, 08:40 AM
Hi Kon,
There seems to be some problem with communication. You don't show your national flag so we don't have that to go by but it seems clear to me that you are struggling to communicate in English as this quote from your first post in this thread will attest:

Basically, I'm going through the entire content of my document to find the character style with the name "Tag". I would like to print out some piece of text, which is in front of the word.

E.g. This is my example text ..... Lets imagine, that I marked the word text. So it would be printed out "This is my example ". And I'm also trying to print out the current page of the match. Is that possible? Thanks a lot for you help.


You might need to take this to the Non English Help forum. We cannot determine your intent from your posts. Please try to tell us exactly what you are trying to do so that folks here can help you.

Most here are frustrated with you so if you want help.....try a little harder to let us in on your thoughts.

As Gerry has pointed out, you should read our FAQ. You say your other thread is solved but you have not marked it solved using the thread tools at the top of the page. This will keep people from spending unnecessary time reading through your thread to try to help you when it has already been solved......

kon
11-19-2007, 12:47 PM
Hey Guys,

@TonyJollans
the solved statement was for my first problem.

@lucas

I couldn't find this kind of button. Can you tell me where I can find this "solved" button? Thanks

Here my problem:

I've created a character style with the name "Tag". With the pieces of code, mentioned above, I'm going through the entire doc file and try to find words that are marked with my character style "Tag". It works fine.

Now, I would like to extend the code. Here an example to make my purpose more understandable:

My example clause contains a word, marked with the character style tag.

At present, just "marked" is printed out. I also would like to get the page, where the character styles has been found and the piece of text (about 20 characters) in the front of the word - here it would be "se contains a work, "

It is true, I'm kind of struggling - of course, it's not my native language :)

Thanks for help!

fumei
11-19-2007, 03:24 PM
I am going to try one more time.

1. Word does not use anything like: marked. There are no tags. If you have [TAG] in front of "marked", then it is text. Word does not "mark" text with a style, at least not in the sense of your open and close tags. I have mentioned this twice, but, shrug....

Text has a style.

2. You can not use things like "about" 20 characters. VBA (or any other programming language) does not do "about". It does what it is told.

I am posting a demo document. You can execute the macro by clicking "MyCharStuff" on the top toolbar.

This is what I have done.

1. The document has a character style, named MyChar. I made it a red font so you can see it easy in the document.
2. There are three instances of it being used.
3. The macro finds those, and displays the found instance, plus the 20 (exactly) characters preceding that found instance.

Please notice that I used Range, not Content. I mentioned this previously, but of course you did not answer.

Here is the entire code.Sub MyCharStuff()
Dim sty As Style
Dim rng As Range

Set rng = ActiveDocument.Range
Set sty = ActiveDocument.Styles("MyChar")

With rng.Find
.ClearFormatting
.Style = sty
Do While .Execute(Forward:=True) = True
rng.MoveStart Unit:=wdCharacter, Count:=-20
MsgBox rng.Text
rng.Collapse Direction:=wdCollapseEnd
Loop
End With
End Sub

Regarding my seeming frustration - and I notice in your last post that you "talked" to Tony and Steve, but not to me - I can not see how you can ignore that you do not answer questions.

From the previous thread, three separate things I posted:

But what, EXACTLY, are you looking for? The whole word? Say the "add" in "yadda" has your style - and by the way, this seems like not a great idea - yes, you could find that. Now what?

Did you answer anything at all? No, you did not.

Describe, EXACTLY, what it is you want to do, or have happen.

Did you answer anything at all? No, you did not.

1. How, EXACTLY, did you make this "style"?
2. How, EXACTLY, are you using it?
3. What, EXACTLY, do you want to do if you find this style?

Did you answer anything at all? No, you did not.

NOTHING. You did not bother answering anything at all.

Yes, there is a language issue, but I am sure we could work through that. Is it such a langauge issue that you can not understand:

What, EXACTLY, do you want to do if you find this style?

It is asking...what do you want to do? Not only do you not bother answering, but you do not bother to even try.

lucas
11-19-2007, 05:51 PM
@lucas

I couldn't find this kind of button. Can you tell me where I can find this "solved" button? Thanks

As further evidence that your are neither listening or answering questions. Please see Post #7 again and look for the part I have marked in red letters.

You are not helping yourself and this thread is close to being closed. Last warning

kon
11-20-2007, 01:42 PM
Hey fumei,
thanks, the piece of code is working fine. I'm not sure, but is it possible to print out additional the page number, where the word was found?
Thanks a lot!

What, EXACTLY, do you want to do if you find this style?
The user is suppose to mark special words with the style. It's just a character style.
If a word is found, I would like to save three information for each found word into an array, first column the word, 20 characters in front of the word in the second column and the page number, where the word was found in the third column.
After I've found all words in the document, I'm going to order the array by the first column characteristically - the first column stores the word.
Finally, I would like to print out the entire array in a table, like the array itself with three columns, to a new word document in the same path. That's what I would like to do :)

The new document is suppose to give an overview to the original one.

@lucas
I got confused at the first and read at the bottom of the page. So I've looked at the bottom of the page and couldn't find anything. Thanks, for the info. I marked the thread as solved.

An other question. Why is this thread close to being closed? I mean, there is a slight communication problem - that's it.

Thanks,
Kon

lucas
11-20-2007, 05:50 PM
An other question. Why is this thread close to being closed? I mean, there is a slight communication problem - that's it.

Thanks,
Kon
Read back through this thread Kon. You inspired some degree of anger from each person who responded. They did help you but it wasn't because YOU are such a nice person. This is carried over from another thread too so I would just ask you to be polite and answer the questions posed. If you don't know how to answer then say that, don't just ignore them and move on with the expectation that they have moved on with you. Much of the miscommunication is not language in nature.

fumei
11-21-2007, 01:25 PM
"If a word is found, I would like to save three information for each found word into an array, first column the word, 20 characters in front of the word in the second column and the page number, where the word was found in the third column.
After I've found all words in the document, I'm going to order the array by the first column characteristically - the first column stores the word.
Finally, I would like to print out the entire array in a table, like the array itself with three columns, to a new word document in the same path. That's what I would like to do "

That could be done.