Re: Help With Code
- From: Fred Goldman <FredGoldman@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 22 Jan 2006 18:33:01 -0800
Scratch that last question. Rather, am I correct if I would say you use Dim
to name a Object as a variable and Set when you want to use a part of a
object (like the name of a paragraph style in your document)?
"Greg Maxey" wrote:
> Fred,
>
> Yes, I neglected to answer your last question. There is nothing wrong with
> it if it is what you want. Say the character style was "underlined."
> Personally I think it would look odd to underline the space after.
>
> --
> Greg Maxey/Word MVP
> See:
> http://gregmaxey.mvps.org/word_tips.htm
> For some helpful tips using Word.
>
>
> Fred Goldman wrote:
> > Helmert,
> >
> > Thank you very much, while Greg gave me working code (thank you,
> > too), you answered a few of the questions I really wanted to know.
> >
> > Just a couple more questions:
> >
> > 1) I've noticed both you are setting variables with "Dim As", what
> > exactly is the difference between "Set" and "Dim As"?
> >
> > 2) What does "Case" mean?
> >
> > 3) I've noticed a lot of people say that they don't want the space
> > after a word tagged with a character style, what is wrong with that?
> >
> >
> > "Helmut Weber" wrote:
> >
> >> Hi Fred,
> >>
> >> try to get used to range-objects.
> >> The macro recorder always uses the selection object,
> >> which may lead beginners to stick to the selection.
> >>
> >> Most often it is not necessary to use selection,
> >> it's also slow and needs too much code to control.
> >>
> >> Use "Option explicit"
> >> see: Tools, Options, Editor, Require Variable Declaration.
> >>
> >>> Set myPara = ActiveDocument.Styles("Body Text2")
> >> This is probably not what you want.
> >> You are creating a style object, IMHO,
> >>> if Selection.Style = myPara
> >> will return false if you modified a paragraph directly,
> >> by e.g. defining a right indent,
> >> as all of the style of the selection is not equal
> >> to all of the style of the template.
> >>
> >> If you use selection.style like
> >> if selection.style = "Normal",
> >> then this returns true, even if you modified the paragraph,
> >> as it checks only for the name of the style, not for all of it.
> >>
> >>> How would I set myPara to more than one style?
> >>
> >> No way. You have to use "or" or "select case".
> >>
> >> if selection.style = "Normal" or selection.style = "Normal2"
> >>
> >> or:
> >>
> >> Sub test500()
> >> Dim oPrg As Paragraph
> >> For Each oPrg In ActiveDocument.Paragraphs
> >> With oPrg.Range.Words(1)
> >> .Select ' for testing using F8, delete after testing!
> >> Select Case oPrg.Style
> >> Case "Normal": .Style = "ChStyle1"
> >> Case "Heading 2": .Style = "ChStyle2"
> >> Case "Heading 3": .Style = "ChStyle3"
> >> End Select
> >> End With
> >> Next
> >> End Sub
> >>
> >>
> >> Greg's code takes care in addition of the fact,
> >> that an ordinary word in Word may encompass a trailing space,
> >> and avoids formatting of the space by setting up a temporary
> >> range, moving the end of the range to the left, and applying
> >> the formatting to the so shortened range.
> >>
> >> Sure, lots of questions left...
> >>
> >> HTH
> >>
> >> --
> >> Greetings from Bavaria, Germany
> >>
> >> Helmut Weber, MVP WordVBA
> >>
> >> Win XP, Office 2003
> >> "red.sys" & Chr$(64) & "t-online.de"
>
>
>
.
- Follow-Ups:
- Re: Help With Code
- From: Jay Freedman
- Re: Help With Code
- From: Greg Maxey
- Re: Help With Code
- References:
- Re: Help With Code
- From: Helmut Weber
- Re: Help With Code
- From: Fred Goldman
- Re: Help With Code
- From: Greg Maxey
- Re: Help With Code
- Prev by Date: Re: Help With Code
- Next by Date: Re: Help With Code
- Previous by thread: Re: Help With Code
- Next by thread: Re: Help With Code
- Index(es):
Relevant Pages
|