Consulting

Results 1 to 10 of 10

Thread: Solved: cumstom style guide

  1. #1
    VBAX Regular
    Joined
    Nov 2007
    Posts
    9
    Location

    Solved: cumstom style guide

    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

  2. #2
    VBAX Mentor OTWarrior's Avatar
    Joined
    Aug 2007
    Location
    England
    Posts
    389
    Location
    i think you need to change
    [vba]Set rng = ActiveDocument.Content[/vba]

    to

    [vba]Set rng = ActiveDocument.Range(Start:=0, End:=50)[/vba]

    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
    -Once my PC stopped working, so I kicked it......Then it started working again

  3. #3
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    What type of style is "tag"? It sounds like you have a paragraph style when you want a character style.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  4. #4
    VBAX Regular
    Joined
    Nov 2007
    Posts
    9
    Location
    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 [TAG]topic[/TAG] .....

    [TAG]- this is line 1[/TAG]
    - this is [TAG]line[/TAG] 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

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

  6. #6
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  7. #7
    VBAX Regular
    Joined
    Nov 2007
    Posts
    9
    Location
    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.

  8. #8
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  9. #9
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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?

  10. #10
    VBAX Regular
    Joined
    Nov 2007
    Posts
    9
    Location
    I changed my style to just characters and now it's working. Thanks a lot! I appreciate your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •