Re: Help With Code



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"
>
>
>
.



Relevant Pages

  • Re: Repeating Loop Until End of Document
    ... Greg, thanks so much! ... Dim i As Long - Declared the variable i as Long. ... Dim oPar as Paragraph is redundant and you can delete it. ... paragraph formatting Exactly 16Pt. ...
    (microsoft.public.word.vba.general)
  • Re: Selection containing complete paragraphs?
    ... Dim p1 As Long ' start of first paragraph in selection ... Dim rtmp As Range ...
    (microsoft.public.word.vba.general)
  • Re: Minimize app vs. Not Visible App
    ... list of numbers, each on its own line (ie, in a paragraph of its own) ... Dim pSrcDoc as Word.Document ... MUCH easier than moving the selection around, ... > until I reach an empty line. ...
    (microsoft.public.word.vba.general)
  • Re: Grabbing previous numbered para
    ... >It is assumed, that you search a selection, not a range. ... >then the selection is in 1 paragraph, ... >Dim oRng As Range ... > Exit Sub ...
    (microsoft.public.word.vba.general)
  • Re: Pivot table field settings
    ... Dim rng As Range ... Greg wrote: ... I assume I would use the current selection object looping through each cell until it reaches the end. ...
    (microsoft.public.excel.programming)