PDA

View Full Version : Solved: cumstom style guide



kon
11-12-2007, 02:51 PM
Hey Guys,
I've created a custom style guide with the name "Tag". I marked some parts of my document with this tag(a entire paragraph, a word or just a character). My purpose is to find all text parts, that are marked with my tag. I found a code snippet on the web , but it lists only paragraphs, that are marked with the tag. So, if I mark just a word or a character, they won't be listed.



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

Is there an other approach to find words or even characters that are marked with the style guide? I've spent already several hours with looking for a solution - I'm desperate :( I'm new to VBA :) I appreciate any help.

Thanks a lot!

Konstantin

OTWarrior
11-13-2007, 03:14 AM
i think you need to change
Set rng = ActiveDocument.Content

to

Set rng = ActiveDocument.Range(Start:=0, End:=50)

the end being what the end of your document is (best to do it dynamically to get the true value).


BTW: welcome to the forum

TonyJollans
11-13-2007, 04:29 AM
What type of style is "tag"? It sounds like you have a paragraph style when you want a character style.

kon
11-13-2007, 01:03 PM
Thanks Guys for your replies. I've tried your suggestion and changed my code to:

Set rng = ActiveDocument.Range(Start:=0, End:=3200)

I just put the 3200 for test purposes - I don't how to get dynamically the end of the document :) But it doesn't change my problem. Here an example:



This is my topic .....

- this is line 1
- this is line 2
- this is line 3


The tag that I've created is inheriting from default - so it's a new tag like TOPIC1, that you can use to give your topics a certain appearance. I hope you understand what kind of tag I mean.

I'm my sample text, just the second like is displayed - so if I mark the entire line with the tag, it will be displayed. That's my actual problem :)

Thanks for help :)

fumei
11-13-2007, 01:16 PM
You do not need to put numbers.

Set rng = ActiveDocument.Range

does just that. It sets rng to be the ActiveDocument Range, regardless of the number.

You seem to be confusing Word styles, with HTML tags.

Word does not mark anything (styles that is) with any sort of opening/closing identifier.

Perhaps start off with describing exactly what you have done.

I've created a custom style guide with the name "Tag". I marked some parts of my document with this tag(a entire paragraph, a word or just a character). I do not know what you mean by "guide".

The fact that you use this for characters sounds like, as Tony mentioned, a character style, but it would help if we actually knew that.

If you are searching at the character level, then that is exactly what you have to do.

Please describe EXACTLY the situation, specificially, to do with characters. You do not have character examples in your example.

This is some yadda text.

OK, say the bolded characters are what you are looking for. 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?

You want the "add", or do you want "yadda"?

If you are searching at the character level, then that is exactly what you get.

This is some yadda text.

"a" is a hit
"d" is a hit
"d" is a hit

Do you want, once you find ANY example - the "a":

Stop
Expand and get the whole word

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

TonyJollans
11-13-2007, 01:55 PM
What Gerry said :)

I'm afraid your second post has left me utterly confused but maybe Gerry is right that you are not understanding the way Word works.

kon
11-13-2007, 04:19 PM
Sorry, that I confused you :) I made screen shot - I hope you understand what kind of tag/style I talking about. I'm not working frequently with word, so I'm not sure about the tag/style expression:)

I used this kind of html tags to point out, that I marked just a certain part of the text. Thanks for help.

TonyJollans
11-14-2007, 02:03 AM
As I said in the first place, Tag is a paragraph style. if you want to use it for individual words you need to have a character style.

fumei
11-14-2007, 12:53 PM
It would also help if you answered questions when they are asked of you.

I will try with some more.

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?

kon
11-14-2007, 01:17 PM
I changed my style to just characters and now it's working. Thanks a lot! I appreciate your help :)